Sum of Numbers
Write a program that asks the user for a positive nonzero integer value. The program should use a loop to get the sum of all the integers from 1 up to the number entered. For example, if the user enters 50, the loop will find the sum of 1, 2, 3, 4, … 50.
Sample output:
init:
deps-jar:
compile-single:
run-single:
Enter a positive nonzero number:
5
The sum of all the integers from 1 through 5 is 15
BUILD SUCCESSFUL (total time: 8 seconds)
so yea what i have is as follows but it wont compile, it tells me Syntax Error : A property cant go after this identifier and it highlights the first line
please help ?
public class sumofnumbers
{
}
system.out.println("Enter a positive number")
int n = n * (n+1) / 2
int i = 0
sum = 0;
for(int i = 0;i <= n; i++)
{
sum=sum+i;
}
System.out.println("Sum is"+sum);

New Topic/Question
Reply




MultiQuote





|