Advertisement
Guest User

Untitled

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