SvetlanPetrova

Walking SoftUni

May 9th, 2021
834
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2.  
  3. public class Walking {
  4.     public static void main(String[] args) {
  5.  
  6.         Scanner scanner = new Scanner(System.in);
  7.  
  8.         String input = "";
  9.         int stepsSum = 0;
  10.         while (stepsSum < 10000 && !"Going home".equals(input = scanner.nextLine())) {
  11.             stepsSum += Integer.parseInt(input);
  12.         }
  13.  
  14.         if ("Going home".equals(input)) {
  15.             stepsSum += Integer.parseInt(scanner.nextLine());
  16.         }
  17.  
  18.         if (stepsSum < 10000) {
  19.             System.out.printf("%d more steps to reach goal.", 10000 - stepsSum);
  20.         } else {
  21.             System.out.printf("Goal reached! Good job!%n%d steps over the goal!", stepsSum - 10000);
  22.         }
  23.  
  24.     }
  25. }
  26.  
RAW Paste Data