Advertisement
Ivelin_Arsov

Walking

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