Write a program that computes the sum of the first ten positive integers,
1 + 2 + • • • + 10. Write a program of the form
public class Sum10
{
public static void main(String[] args)
{
System.out.println();
}
}
1
Expert's answer
2013-07-23T09:33:15-0400
//Write a program that computes the sum of the first tenpositive //integers, //1 + 2 + • • • + 10. public class Sum10 { public staticvoid main(String[] args) { System.out.println(sum(1,10)); }
public staticint sum(int start, int end) { int res=0; for (int i = start; i <= end; i++) { res+=i; }
Comments
Leave a comment