Advertisement
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);
- //Стоп:
- // 1.стъпки >= 10000 2. команда == "Going home"
- //команда -> Going home или число (стъпки)
- int totalSteps = 0;
- while (totalSteps < 10000) {
- String command = scanner.nextLine();
- if(command.equals("Going home")){
- int stepsToHome = Integer.parseInt(scanner.nextLine());
- totalSteps += stepsToHome;
- break;
- } else {
- //команда -> число ("2000") -> command = "2000"
- //стринг -> цяло числo
- int steps = Integer.parseInt(command); //колко стъпки е извървяла
- //сумираме стъпките
- totalSteps += steps;
- }
- }
- //ако командата стане Going home
- //проверка дали е постигнала целта
- if(totalSteps >= 10000){
- System.out.println("Goal reached! Good job!");
- int moreSteps = totalSteps - 10000;
- System.out.printf("%d steps over the goal!", moreSteps);
- } else {
- int diffSteps = 10000 - totalSteps;
- System.out.printf("%d more steps to reach goal.", diffSteps);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement