Advertisement
mark79

High Jump

Jul 23rd, 2019
560
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.09 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class HighJump {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         int height = scanner.nextInt();
  8.  
  9.         int currentHeight = height - 30;
  10.  
  11.         int totalJumps = 0;
  12.         boolean failed = false;
  13.  
  14.         int counterFailed = 0;
  15.  
  16.         while (!failed) {
  17.             int jump = scanner.nextInt();
  18.             totalJumps++;
  19.  
  20.             if (jump <= currentHeight) {
  21.                 counterFailed++;
  22.                 if (counterFailed == 3) {
  23.                     failed = true;
  24.                 }
  25.             } else {
  26.                 if (currentHeight >= height) {
  27.                     break;
  28.                 }
  29.                 currentHeight += 5;
  30.                 counterFailed = 0;
  31.             }
  32.         }
  33.  
  34.         if (!failed) {
  35.             System.out.printf("Tihomir succeeded, he jumped over %dcm after %d jumps.", currentHeight, totalJumps);
  36.         } else {
  37.             System.out.printf("Tihomir failed at %dcm after %d jumps.", currentHeight, totalJumps);
  38.         }
  39.  
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement