Advertisement
Spocoman

05. Game Of Intervals

Aug 28th, 2024
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.75 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class GameOfIntervals {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int n = Integer.parseInt(scanner.nextLine());
  7.         int num0To10 = 0;
  8.         int num10To20 = 0;
  9.         int num20To30 = 0;
  10.         int num30To40 = 0;
  11.         int num40To50 = 0;
  12.         int invalidNum = 0;
  13.         double result = 0;
  14.  
  15.         for (int i = 0; i < n; i++) {
  16.             double number = Double.parseDouble(scanner.nextLine());
  17.             if (number >= 0 && number < 10) {
  18.                 result += number * 0.2;
  19.                 num0To10++;
  20.             } else if (number >= 10 && number < 20) {
  21.                 result += number * 0.3;
  22.                 num10To20++;
  23.             } else if (number >= 20 && number < 30) {
  24.                 result += number * 0.4;
  25.                 num20To30++;
  26.             } else if (number >= 30 && number < 40) {
  27.                 result += 50;
  28.                 num30To40++;
  29.             } else if (number >= 40 && number <= 50) {
  30.                 result += 100;
  31.                 num40To50++;
  32.             } else{
  33.                 result /= 2;
  34.                 invalidNum++;
  35.             }
  36.         }
  37.  
  38.         System.out.printf("%.2f\n", result);
  39.         System.out.printf("From 0 to 9: %.2f%%\n", (double)num0To10 / n * 100);
  40.         System.out.printf("From 10 to 19: %.2f%%\n", (double)num10To20 / n * 100);
  41.         System.out.printf("From 20 to 29: %.2f%%\n",(double)num20To30 / n * 100);
  42.         System.out.printf("From 30 to 39: %.2f%%\n", (double)num30To40 / n * 100);
  43.         System.out.printf("From 40 to 50: %.2f%%\n", (double)num40To50 / n * 100);
  44.         System.out.printf("Invalid numbers: %.2f%%\n", (double)invalidNum / n * 100);
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement