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