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 scan = new Scanner(System.in);
- int stepCount = 0;
- while (true) {
- String command = scan.nextLine();
- if (command.equals("Going home")) {
- int lastSteps = Integer.parseInt(scan.nextLine());
- stepCount += lastSteps;
- if (stepCount >= 10000) {
- System.out.println("Goal reached! Good job!");
- return;
- } else {
- System.out.printf("%d more steps to reach goal.", 10000 - stepCount);
- return;
- }
- }
- int momentSteps = Integer.parseInt(command);
- stepCount += momentSteps;
- if (stepCount >= 10000) {
- System.out.println("Goal reached! Good job!");
- return;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment