SHARE
TWEET

Untitled

dagrizzly Jul 23rd, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.company;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class HighJump {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         int goal = Integer.parseInt(scanner.nextLine());
  10.         int currentHeight = goal - 30;
  11.         int jumpCounter = 0;
  12.         int fails = 0;
  13.  
  14.         boolean endProgram = false;
  15.  
  16.  
  17.  
  18.         while (!endProgram){
  19.             for(int i=1; i <= 3; i++){
  20.                 int currentAtempt = Integer.parseInt(scanner.nextLine());
  21.                 jumpCounter++;
  22.                 if (currentAtempt > goal) {
  23.                     System.out.printf("Tihomir succeeded, he jumped over %dcm after %d jumps.", goal, jumpCounter);
  24.                     endProgram = true;
  25.                     break;
  26.                 } else if (currentAtempt > currentHeight) {
  27.                     currentHeight = currentHeight + 5;
  28.                     fails = 0;
  29.                     break;
  30.                 } else {
  31.                     fails++;
  32.                 }
  33.                 if(fails == 3){
  34.                     System.out.printf("Tihomir failed at %dcm after %d jumps.", currentHeight, jumpCounter);
  35.                     endProgram = true;
  36.                     break;
  37.                 }
  38.  
  39.             }
  40.         }
  41.     }
  42. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top