Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.77 KB | None | 0 0
  1. package WhileLoopExercise;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Walking {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.         String input = scanner.nextLine();
  9.         int goal = 10000;
  10.         int stepsCounter = 0;
  11.  
  12.         while (stepsCounter <= goal) {
  13.             int steps = Integer.parseInt(input);
  14.             stepsCounter += steps;
  15.             if (input.equals("Going home")) {
  16.                 break;
  17.             }
  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