Advertisement
Spocoman

High Jump

Sep 7th, 2024
490
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.88 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int jumpTarget = Integer.parseInt(scanner.nextLine()),
  7.                 jump, startJump = jumpTarget - 30, counter = 0, fall = 0;
  8.  
  9.         while (fall != 3 && startJump <= jumpTarget) {
  10.             jump = Integer.parseInt(scanner.nextLine());
  11.             if (jump > startJump) {
  12.                 startJump += 5;
  13.                 fall = 0;
  14.             } else {
  15.                 fall++;
  16.             }
  17.             counter++;
  18.         }
  19.  
  20.         if (startJump <= jumpTarget) {
  21.             System.out.println("Tihomir failed at " + startJump + "cm after " + counter + " jumps.");
  22.         } else {
  23.             System.out.println("Tihomir succeeded, he jumped over " + jumpTarget + "cm after " + counter + " jumps.");
  24.         }
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement