Advertisement
CoineTre

04.Walking

Nov 12th, 2020
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.94 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Walking {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         String steps = scanner.nextLine();
  7.         int stepsSum=0;
  8.         while(!steps.equals("Going home")){
  9.             int todaySteps = Integer.parseInt(steps);
  10.             stepsSum +=todaySteps;
  11.             if (stepsSum >=10000){
  12.                 break;
  13.             }
  14.             steps = scanner.nextLine();
  15.         }
  16.         if (steps.equals("Going home")){
  17.             int stepsToHome = Integer.parseInt(scanner.nextLine());
  18.             stepsSum +=stepsToHome;
  19.         }
  20.         if (stepsSum >= 10000){
  21.             int moreSteps = stepsSum - 10000;
  22.             System.out.println("Goal reached! Good job!");
  23.             System.out.printf("%d steps over the goal!",moreSteps);
  24.         }else{
  25.             System.out.printf("%d more steps to reach goal.",10000-stepsSum);
  26.         }
  27.     }
  28. }
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement