desislava_topuzakova

06. High Jump с While

Mar 20th, 2021
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class ExamPreparation {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6. int target = Integer.parseInt(scanner.nextLine());
  7.  
  8. int startHeight = target - 30;
  9. int totalJumps = 0;
  10. while(startHeight <= target) {
  11. //височина -> 3 скока
  12. int failedJumps = 0;
  13. for (int jump = 1; jump <= 3 ; jump++) {
  14. int jumpHeight = Integer.parseInt(scanner.nextLine());
  15. totalJumps++;
  16. if(jumpHeight > startHeight) {
  17. //успешен опит и спира да скача на тази височина
  18. startHeight += 5;
  19. break;
  20. } else {
  21. //неуспешен опит
  22. failedJumps++;
  23. }
  24. }
  25. if(failedJumps == 3) {
  26. System.out.printf("Tihomir failed at %dcm after %d jumps.", startHeight, totalJumps);
  27. return;
  28. }
  29.  
  30. }
  31.  
  32. System.out.printf("Tihomir succeeded, he jumped over %dcm after %d jumps.", target, totalJumps);
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment