Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.Scanner;
- public class HighJump {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int goal = Integer.parseInt(scanner.nextLine());
- int currentHeight = goal - 30;
- int jumpCounter = 0;
- int fails = 0;
- boolean endProgram = false;
- while (!endProgram){
- for(int i=1; i <= 3; i++){
- int currentAtempt = Integer.parseInt(scanner.nextLine());
- jumpCounter++;
- if (currentAtempt > goal) {
- System.out.printf("Tihomir succeeded, he jumped over %dcm after %d jumps.", goal, jumpCounter);
- endProgram = true;
- break;
- } else if (currentAtempt > currentHeight) {
- currentHeight = currentHeight + 5;
- fails = 0;
- break;
- } else {
- fails++;
- }
- if(fails == 3){
- System.out.printf("Tihomir failed at %dcm after %d jumps.", currentHeight, jumpCounter);
- endProgram = true;
- break;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement