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