Advertisement
Spocoman

04. Walking

Aug 29th, 2024
366
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.74 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Walking {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int neededSteps = 10000;
  7.  
  8.         String input;
  9.         while (neededSteps > 0) {
  10.             input = scanner.nextLine();
  11.             if (input.equals("Going home")) {
  12.                 neededSteps -= Integer.parseInt(scanner.nextLine());
  13.                 break;
  14.             }
  15.             neededSteps -= Integer.parseInt(input);
  16.         }
  17.  
  18.         if (neededSteps > 0) {
  19.             System.out.printf("%d more steps to reach goal.\n", neededSteps);
  20.         } else {
  21.             System.out.printf("Goal reached! Good job!\n%d steps over the goal!", Math.abs(neededSteps));
  22.         }
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement