Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
72
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 Main {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         int goal = 10000;
  8.         int stepsCounter = 0;
  9.  
  10.         while (stepsCounter <= goal) {
  11.             String input = scanner.nextLine();
  12.  
  13.             if (input.equals("Going home")) {
  14.                 break;
  15.             }
  16.             int steps = Integer.parseInt(input);
  17.             stepsCounter += steps;
  18.         }
  19.  
  20.         if (input.equals("Going home")) {
  21.             int moreStepsNeeded = goal - stepsCounter;
  22.             System.out.printf("%d more steps to reach goal.", moreStepsNeeded);
  23.         } else {
  24.             System.out.println("Goal reached! Good job!");
  25.         }
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement