la-ma-rin

walking

Nov 7th, 2018
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.97 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class walking {
  4.     public static void main(String[] args) {
  5.         Scanner scan = new Scanner(System.in);
  6.  
  7.         int stepCount = 0;
  8.  
  9.         while (true) {
  10.             String command = scan.nextLine();
  11.  
  12.             if (command.equals("Going home")) {
  13.                 int lastSteps = Integer.parseInt(scan.nextLine());
  14.                 stepCount += lastSteps;
  15.                 if (stepCount >= 10000) {
  16.                     System.out.println("Goal reached! Good job!");
  17.                     return;
  18.                 } else {
  19.                     System.out.printf("%d more steps to reach goal.", 10000 - stepCount);
  20.                     return;
  21.                 }
  22.             }
  23.             int momentSteps = Integer.parseInt(command);
  24.             stepCount += momentSteps;
  25.  
  26.             if (stepCount >= 10000) {
  27.                 System.out.println("Goal reached! Good job!");
  28.                 return;
  29.             }
  30.         }
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment