Hi ALL,
Here I wrote a program for Sum of Number for given limit in java.
/**
*
* @author Balamurgan
M
*/
public class method1 {
public static void
main(String arg[]){
System.out.println(" Sum of Number for given limit ");
System.out.println(" Sum of 1 to 10 "+sum(1,10));
System.out.println(" Sum of 1 to 10 "+sum(25,35));
System.out.println(" Sum of 1 to 10 "+sum(40,50));
}
private static int
sum(int num1,int num2){
int
sum_1=0;
for(int
i=num1;i<=num2;i++)
sum_1 +=i;
return sum_1;
}
}
No comments:
Post a Comment