- #1
Math10
- 301
- 0
Write a Java program to find the sum of all numbers between 1 to 10.
So we all know that 1+2+3+4+5+6+7+8+9+10=55 and that answer to this problem is 55. Please check my work below:
Did I wrote this program correctly? If not, then please correct me. Thanks.
So we all know that 1+2+3+4+5+6+7+8+9+10=55 and that answer to this problem is 55. Please check my work below:
Java:
public class Standard
{
public static void main(String[] args)
{
// Create a for loop.
for (int x=1; x<=10; x=x+1)
{
// Print result.
System.out.println("Sum of numbers from 1 to 10 is" x=x+1);
}
}
}
Did I wrote this program correctly? If not, then please correct me. Thanks.
Last edited by a moderator: