0
I need someone to help me calculate the sum of integers from 1 to 10 in java
I'm having exams in 4 hours time and I need to understand how to calculate the sum. It could be different but I'm sure the exam question will bear thesame syntax.
2 Antworten
+ 6
Hello Chukscomax Nnadiekwe
Just use a for loop which starts at 1 and ends at 10.
0
int sum = 0;
for(int n = 1; n <= 10; n++) {
sum += n;
}
in the end print sum
System.out.print(sum);
In case you have an int func then
return sum;