الرجوع
تسجيل الدخول

What is the output of the following code?

int number = 0;
int sum = 0;
Scanner scanner = new Scanner(System.in);

while (number != -1) {
    System.out.print("Enter a number (-1 to quit): ");
    number = scanner.nextInt();
    if (number != -1) {
        sum += number;
    }
}
System.out.println("Sum: " + sum);