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