Advertisement
Deiancom

Walking

Feb 12th, 2020
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.99 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.         String steps = scan.nextLine();
  7.         int stepsCnt = 0;
  8.         int allSteps = 0;
  9.  
  10.         while (allSteps < 10000) {
  11.  
  12.             if (!steps.equals("Going home")) {
  13.                 stepsCnt = Integer.parseInt(steps);
  14.                 allSteps += stepsCnt;
  15.                 if (allSteps >= 10000) {
  16.                    
  17.                     break;
  18.                 }
  19.                 steps = scan.nextLine();
  20.  
  21.             } else {
  22.                 steps = scan.nextLine();
  23.                 stepsCnt = Integer.parseInt(steps);
  24.                 allSteps = allSteps + stepsCnt;
  25.                 break;
  26.  
  27.  
  28.             }
  29.         }
  30.         if (allSteps < 10000) {
  31.             System.out.printf("%d more steps to reach goal.", 10000 - allSteps);
  32.         } else {
  33.             System.out.println("Goal reached! Good job!");
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement