Advertisement
Guest User

Untitled

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