EliPerfanova

Walking

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