Ligh7_of_H3av3n

05. Everest

Oct 15th, 2023
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.06 KB | None | 0 0
  1. package PodgotovkaZaIzpit;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Everest {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         int startHeight = 5364;
  10.         int target = 8848;
  11.         int curentHeight = 0;
  12.         int count = 1;
  13.         while (true) {
  14.             String yesOrNo = scanner.nextLine();
  15.             if (yesOrNo.equals("END")) {
  16.                 break;
  17.             }
  18.             if (yesOrNo.equals("Yes")) {
  19.                 count++;
  20.             }
  21.             int height = Integer.parseInt(scanner.nextLine());
  22.             curentHeight += height;
  23.             if (curentHeight + startHeight >= target) {
  24.                 break;
  25.             }
  26.             if (count == 5) {
  27.                 break;
  28.             }
  29.         }
  30.         if (startHeight + curentHeight < target) {
  31.             System.out.println("Failed!");
  32.             System.out.printf("%d", startHeight + curentHeight);
  33.         } else {
  34.             System.out.printf("Goal reached for %d days!", count);
  35.         }
  36.     }
  37. }
  38.  
Add Comment
Please, Sign In to add comment