Advertisement
marking2112

Walking

Jul 4th, 2018
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.92 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class P05_Walking {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         String input = scanner.nextLine();
  8.         int sum = 0;
  9.  
  10.         while (!"Going home".equals(input)) {
  11.             int steps = Integer.parseInt(input);
  12.             sum += steps;
  13.             if (sum >= 10000) {
  14.                 System.out.println("Goal reached! Good job!");
  15.                 break;
  16.             }
  17.             input = scanner.nextLine();
  18.         }
  19.        
  20.         if ("Going home".equals(input)) {
  21.             int lastSteps = Integer.parseInt(scanner.nextLine());
  22.             int result = 10000 - (sum + lastSteps);
  23.             if (result > 0) {
  24.                 System.out.printf("%d more steps to reach goal.", result);
  25.             } else {
  26.                 System.out.println("Goal reached! Good job!");
  27.             }
  28.  
  29.         }
  30.  
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement