Answer to Question #33426 in Java | JSP | JSF for Jimbo

Question #33426
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;
}

return res;
}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS