Created
September 13, 2020 22:00
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
class Main { | |
public static void main(String[] args) { | |
Scanner scanner = new Scanner(System.in); | |
int sum = 0; | |
int num; | |
boolean barrier = false; | |
while (!barrier) { | |
num = scanner.nextInt(); | |
sum += num; | |
barrier = sum >= 1000; | |
if (barrier) { | |
sum -= 1000; | |
} else if (num == 0) { | |
break; | |
} | |
} | |
System.out.println(sum); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment