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