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