Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class ExamHighJump {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int desiredHeight = Integer.parseInt(scanner.nextLine());
- int beginningHeight = desiredHeight - 30;
- int totalJumps = 0;
- int totalUnsuccessfulJumps = 0;
- while (true) {
- int jump = Integer.parseInt(scanner.nextLine());
- totalJumps++;
- if (jump <= beginningHeight) { // not successful
- totalUnsuccessfulJumps++;
- if (totalUnsuccessfulJumps == 3) {
- System.out.printf("Tihomir failed at %dcm after %d jumps.", beginningHeight, totalJumps);
- break;
- }
- } else {
- beginningHeight = beginningHeight + 5; // successful
- totalUnsuccessfulJumps = 0;
- }
- if (beginningHeight > desiredHeight) {
- System.out.printf("Tihomir succeeded, he jumped over %dcm after %d jumps.", desiredHeight, totalJumps);
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement