Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package _05_WhileLoops;
- import java.util.Scanner;
- public class Walking {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int goal = 10000;
- while (goal > 0) {
- String input = scanner.nextLine();
- if (input.equals("Going home")) {
- int tiredSteps = Integer.parseInt(scanner.nextLine());
- goal -= tiredSteps;
- break;
- }
- int steps = Integer.parseInt(input);
- goal = goal - steps;
- // goal -= steps;
- }
- if (goal <= 0) {
- System.out.printf("Goal reached! Good job!%n" +
- "%d steps over the goal!", Math.abs(goal));
- } else {
- System.out.printf("%d more steps to reach goal.", goal);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement