Advertisement
dagrizzly

Untitled

Jul 23rd, 2019
347
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.05 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class HighJump2 {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.  
  10.         int goalBarHeight  =  Integer.parseInt(scanner.nextLine());
  11.         int currentBarHeight = goalBarHeight - 30;
  12.         int countFails = 0;
  13.  
  14.         for (int i=1; ;i++){
  15.             int currentAttempt = Integer.parseInt(scanner.nextLine());
  16.             if (currentAttempt > goalBarHeight && (currentBarHeight + 5) >= goalBarHeight){
  17.                 System.out.printf("Tihomir succeeded, he jumped over %dcm after %d jumps.", goalBarHeight, i);
  18.                 break;
  19.             } else if (currentAttempt > currentBarHeight){
  20.                 currentBarHeight += 5;
  21.                 countFails = 0;
  22.             } else {
  23.                 countFails++;
  24.                 if (countFails == 3){
  25.                     System.out.printf("Tihomir failed at %dcm after %d jumps.", currentBarHeight, i);
  26.                     break;
  27.                 }
  28.             }
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement