Advertisement
myrdok123

06. World Swimming Record

Jan 14th, 2024 (edited)
737
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.13 KB | None | 0 0
  1. package W02ConditionalStatements.Exercises;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class P06WorldSwimmingRecord {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         double recordInSeconds = Double.parseDouble(scanner.nextLine());
  10.         double distance = Double.parseDouble(scanner.nextLine());
  11.         double timeForOneMeter = Double.parseDouble(scanner.nextLine());
  12.  
  13.  
  14.         //Пресмятаме забавянето -> за всеки 15 метра той се забавя 12.5 секунди
  15.         double delay = (Math.floor(distance / 15)) * 12.5;
  16.  
  17.         //Пресмятаме резултата от плуването
  18.         double result = distance * timeForOneMeter + delay;
  19.  
  20.         //Проверяваме дали рекордът е подобрен
  21.         if(result < recordInSeconds){
  22.             System.out.printf("Yes, he succeeded! The new world record is %.2f seconds.", result);
  23.         }else {
  24.             double diff = result - recordInSeconds;
  25.             System.out.printf("No, he failed! He was %.2f seconds slower.", diff);
  26.         }
  27.     }
  28. }
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement