Advertisement
Rayk

Walking

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