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