Advertisement
Guest User

Untitled

a guest
Jul 28th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.33 KB | None | 0 0
  1. public static int returnSumUntil42(Scanner input) {
  2. boolean seen42 = false;
  3. int total = 0;
  4. int num = 0;
  5. while (input.hasNext() == true) {
  6. num = input.nextInt();
  7. if (num == 42) {
  8. seen42 = true;
  9. }
  10. if (seen42 == false) {
  11. total += num;
  12. }
  13. }
  14. return total;
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement