Advertisement
deyanivanov966

04. Walking

Apr 1st, 2021
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.69 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Walking {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         String input = null;
  8.         int step = 0;
  9.         while (step < 10000 && !"Going home".equals(input = scanner.nextLine())) {
  10.             step += Integer.parseInt(input);
  11.         }
  12.  
  13.         if ("Going home".equals(input)) {
  14.             step += Integer.parseInt(scanner.nextLine());
  15.         }
  16.  
  17.         if (step < 10000) {
  18.             System.out.printf("%d more steps to reach goal.", 10000 - step);
  19.         } else {
  20.             System.out.printf("Goal reached! Good job!%n%d steps over the goal!", step - 10000);
  21.         }
  22.     }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement