0
Can anyone explain how my strange code works?
I was working on homework for my Computer Science class, when I stumbled upon this problem and got a result of 55. https://code.sololearn.com/csXVMW15w1KI/?ref=app
3 Réponses
+ 4
public class Strange {
public static final int MAX = 5;
public static void unknown() {
int number = 0;
for (int count = MAX; count >= 1; count--) {
number += (count * count);
}
System.out.println("The result is: " + number);
}
public static void main(String[] args) {
unknown();
}
}
count: 5, number: 25
count: 4, number: 25 + 16
count: 3, number: 41 + 9
count: 2, number: 50 + 4
count: 1, number: 54 + 1
count: 0, loop terminates
number: 55