The integer barrier

Report a typo

Write a program that inputs a sequence of integer numbers in a loop and calculates their sum under the following conditions:

1) if a new number is 0, the program must stop the loop and output the accumulated sum;

2) if the sum is equal to or exceeds the limit of 1000, the program must also stop reading the numbers and output the value equal to the sum minus 1000.

Note: the input can contain extra numbers. Just ignore them.

Sample Input 1:

800
101
102
300
0

Sample Output 1:

3

Sample Input 2:

103
105
109
0
1000

Sample Output 2:

317
Write a program in Java 17
import java.util.Scanner;

class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// start coding here
}
}
___

Create a free account to access the full topic