Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static int returnSumUntil42(Scanner input) {
- boolean seen42 = false;
- int total = 0;
- int num = 0;
- while (input.hasNext() == true) {
- num = input.nextInt();
- if (num == 42) {
- seen42 = true;
- }
- if (seen42 == false) {
- total += num;
- }
- }
- return total;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement