Advertisement
psi_mmobile

Untitled

May 15th, 2022
831
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.00 KB | None | 0 0
  1.  //5.   Игра на интервали
  2. public class MyClass {
  3.     public static void main(String args[]) {
  4.        java.util.Scanner scanner = new java.util.Scanner(System.in);
  5.        int turns = scanner.nextInt();
  6.        
  7.        double finalScore = 0.0;
  8.        
  9.        int numbersFrom0to9 = 0;
  10.        int numbersFrom10to19 = 0;
  11.        int numbersFrom20to29 = 0;
  12.        int numbersFrom30to39 = 0;
  13.        int numbersFrom40to50 = 0;
  14.        int numbersInvalid = 0;
  15.        
  16.        int number = 0;
  17.        
  18.        for (int i = 1; i <= turns; i++) {
  19.            number = scanner.nextInt();
  20.            if (number >= 0 && number <= 9) {
  21.                numbersFrom0to9++;
  22.                finalScore += 0.2 * number;
  23.            }
  24.             else if (number >= 10 && number <= 19) {
  25.                numbersFrom10to19++;
  26.                finalScore += 0.3 * number;
  27.            }
  28.            else if (number >= 20 && number <= 29) {
  29.                numbersFrom20to29++;
  30.                finalScore += 0.4 * number;
  31.            }
  32.            else if (number >= 30 && number <= 39) {
  33.                numbersFrom30to39++;
  34.                finalScore += 50;
  35.            }
  36.            else if (number >= 40 && number <= 50) {
  37.                numbersFrom40to50++;
  38.                finalScore += 100;
  39.            }
  40.            else {
  41.                numbersInvalid++;
  42.                finalScore = finalScore * 0.5;
  43.            }
  44.        }
  45.        System.out.printf("%.2f\n",finalScore);
  46.        System.out.printf("From 0 to 9: %.2f%%\n", (double)numbersFrom0to9/turns * 100);
  47.        System.out.printf("From 10 to 19: %.2f%%\n", (double)numbersFrom10to19/turns * 100);
  48.        System.out.printf("From 20 to 29: %.2f%%\n", (double)numbersFrom20to29/turns * 100);
  49.        System.out.printf("From 30 to 39: %.2f%%\n", (double)numbersFrom30to39/turns * 100);
  50.        System.out.printf("From 40 to 50: %.2f%%\n", (double)numbersFrom40to50/turns * 100);
  51.        System.out.printf("Invalid numbers: %.2f%%\n", (double)numbersInvalid/turns * 100);
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement