Advertisement
AngelKejov

Untitled

Apr 4th, 2021
99
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package Exercises;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Walking {
  6.  
  7.     public static void main(String[] args) {
  8.         Scanner sc = new Scanner(System.in);
  9.  
  10.         int stepsGoal = 10000;
  11.  
  12.         while (true) {
  13.             String input = sc.nextLine();
  14.             if (!input.equals("Going home")) {
  15.                 int steps = Integer.parseInt(input);
  16.                 stepsGoal -= steps;
  17.                 if (stepsGoal <= 0) {
  18.                     int diff = Math.abs(stepsGoal);
  19.                     System.out.printf("Goal reached! Good job!\n" +
  20.                             "%d steps over the goal!", diff);
  21.                     break;
  22.                 }
  23.             } else {
  24.                 int stepsToHome = Integer.parseInt(sc.nextLine());
  25.                 stepsGoal -= stepsToHome;
  26.                 if (stepsGoal > 0) {
  27.                     int diff = Math.abs(stepsGoal);
  28.                     System.out.printf("%d more steps to reach goal.", diff);
  29.                     break;
  30.                 }
  31.             }
  32.         }
  33.     }
  34. }
  35.  
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement