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