Advertisement
galinyotsev123

ProgBasicsExam9and10March2019-E06highJump

Mar 17th, 2019
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.  
  5. public static void main(String[] args) {
  6. Scanner scanner = new Scanner(System.in);
  7.  
  8. int targetHeight = Integer.parseInt(scanner.nextLine());
  9. int jumpsCounter = 0;
  10. int unsuccessfulTries = 0;
  11. int barHeight = targetHeight - 30;
  12. boolean isFailed = false;
  13.  
  14.  
  15. for (int i = 0; i <= 3; i++) {
  16. jumpsCounter++;
  17.  
  18. int jumpHeight = Integer.parseInt(scanner.nextLine());
  19.  
  20. if (barHeight < jumpHeight) {
  21. if (barHeight >= targetHeight) {
  22. break;
  23. }
  24. barHeight += 5;
  25. if (i > 0) {
  26. unsuccessfulTries = 0;
  27. }
  28. i = 0;
  29. } else {
  30. unsuccessfulTries += 1;
  31. if (unsuccessfulTries == 3) {
  32. isFailed = true;
  33. break;
  34. }
  35. }
  36. }
  37.  
  38. if (!isFailed) {
  39. System.out.printf("Tihomir succeeded, he jumped over %dcm after %d jumps.", barHeight, jumpsCounter);
  40. } else {
  41. System.out.printf("Tihomir failed at %dcm after %d jumps.", barHeight, jumpsCounter);
  42. }
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement