Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Walking_04 {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- //СТОП: стъпки >= 10000 -> продължава:стъпки < 10000
- //СТОП: команда = "Going home"
- int steps = 0;
- boolean isGoingHome = false;
- //false -> не отива към вкъщи, true -> отива към вкъщи
- while(steps < 10000){
- String command = scanner.nextLine(); // Going home или число, което са стъпките
- if(command.equals("Going home")){
- int stepsToHome = Integer.parseInt(scanner.nextLine());
- steps += stepsToHome;
- isGoingHome = true;
- break;
- } else {
- //"1500" -> стринг към инт -> парсване
- int walkedSteps = Integer.parseInt(command);
- steps += walkedSteps;
- }
- }
- //ако постигне целта си
- if(steps >= 10000){
- System.out.println("Goal reached! Good job!");
- } else if(isGoingHome){
- int leftSteps = 10000 - steps;
- System.out.printf("%d more steps to reach goal.", leftSteps);
- }
- }
- }
Add Comment
Please, Sign In to add comment