SvetlanPetrova

CarRace Array SoftUni

Jul 9th, 2021
914
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.07 KB | None | 0 0
  1. import java.util.Arrays;
  2. import java.util.Scanner;
  3.  
  4. public class CarRace {
  5.     public static void main(String[] args) {
  6.         Scanner scanner = new Scanner(System.in);
  7.  
  8.         int numbers[] = Arrays.stream(scanner.nextLine().split("\\s+"))
  9.                 .mapToInt(Integer::parseInt).toArray();
  10.  
  11.         double timeLeft = 0;
  12.         double timeRight = 0;
  13.  
  14.         for (int i = 0; i < numbers.length/2; i++) {
  15.             if (numbers[i] == 0) {
  16.                 timeLeft = timeLeft * 0.8;
  17.             }
  18.             timeLeft +=numbers[i];
  19.         }
  20.  
  21.         for (int j = numbers.length-1; j > (numbers.length - numbers.length/2 -1); j--) {
  22.             if (numbers[j] == 0) {
  23.                 timeRight = timeRight * 0.8;
  24.             }
  25.             timeRight += numbers[j];
  26.         }
  27.  
  28.         if (timeLeft < timeRight) {
  29.             System.out.printf("The winner is left with total time: %.1f", timeLeft);
  30.         }
  31.         else if (timeRight < timeLeft) {
  32.             System.out.printf("The winner is right with total time: %.1f", timeRight);
  33.         }
  34.  
  35.     }
  36. }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment