Advertisement
Spocoman

Walking

Sep 10th, 2024
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.69 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  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.println("Goal reached! Good job!");
  20.         } else {
  21.             System.out.println(neededSteps + " more steps to reach goal.");
  22.         }
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement