public class MyProgram { public void start() { int sum = 0; System.out.println("Enter number: "); int num = Integer.parseInt(Keyboard.readInput()); while (num >= 0) { sum = sum + num; System.out.print("Enter number: "); num = Integer.parseInt(Keyboard.readInput()); sum++; } System.out.println("Sum: " + sum); } }
first loop, num = 3 sum = sum + num // sum becomes 3 sum++ // sum becomes 4 second loop, num = 2 sum = sum + num // sum becomes 6 sum++ // sum becomes 7
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)