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