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

15th Sep 2019, 5:57 PM
Santiago Bermudez
Santiago Bermudez - avatar
1 Antwort
+ 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
15th Sep 2019, 6:08 PM
Anton Böhler
Anton Böhler - avatar