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.

3rd Jul 2021, 9:12 AM
Chukscomax Nnadiekwe
Chukscomax Nnadiekwe - avatar
2 Antworten
+ 6
Hello Chukscomax Nnadiekwe Just use a for loop which starts at 1 and ends at 10.
3rd Jul 2021, 9:20 AM
Denise Roßberg
Denise Roßberg - avatar
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;
3rd Jul 2021, 10:25 AM
Jimmy Phoitick
Jimmy Phoitick - avatar