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