Advertisement
silviasj

High Jump

May 24th, 2020
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.15 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class ExamHighJump {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         int desiredHeight = Integer.parseInt(scanner.nextLine());
  8.         int beginningHeight = desiredHeight - 30;
  9.  
  10.         int totalJumps = 0;
  11.  
  12.         int totalUnsuccessfulJumps = 0;
  13.         while (true) {
  14.             int jump = Integer.parseInt(scanner.nextLine());
  15.             totalJumps++;
  16.  
  17.  
  18.  
  19.             if (jump <= beginningHeight) { // not successful
  20.                 totalUnsuccessfulJumps++;
  21.                 if (totalUnsuccessfulJumps == 3) {
  22.                     System.out.printf("Tihomir failed at %dcm after %d jumps.", beginningHeight, totalJumps);
  23.                     break;
  24.                 }
  25.             } else {
  26.                beginningHeight = beginningHeight + 5; // successful
  27.                 totalUnsuccessfulJumps = 0;
  28.             }
  29.             if (beginningHeight > desiredHeight) {
  30.                 System.out.printf("Tihomir succeeded, he jumped over %dcm after %d jumps.", desiredHeight, totalJumps);
  31.                 break;
  32.             }
  33.  
  34.  
  35.         }
  36.  
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement