Advertisement
psi_mmobile

Untitled

May 7th, 2022
1,105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.38 KB | None | 0 0
  1. public class MyClass {
  2.     public static void main(String args[]) {
  3.         java.util.Scanner scanner = new java.util.Scanner(System.in);
  4.         int numberCount = scanner.nextInt();
  5.         int p1 = 0;
  6.         int p2 = 0;
  7.         int p3 = 0;
  8.         int p4 = 0;
  9.         int p5 = 0;
  10.         int nextNumber = 0;
  11.         for (int i = 0; i < numberCount; i++) {
  12.             nextNumber = scanner.nextInt();
  13.             if (nextNumber < 200) {
  14.                 p1++;
  15.             }
  16.             if (nextNumber >= 200 && nextNumber < 400) {
  17.                 p2++;
  18.             }
  19.             if (nextNumber >= 400 && nextNumber < 600) {
  20.                 p3++;
  21.             }
  22.             if (nextNumber >= 600 && nextNumber < 800) {
  23.                 p4++;
  24.             }
  25.             if (nextNumber >= 800) {
  26.                 p5++;
  27.             }
  28.         }
  29.        
  30.         double p1Part = (double) p1/numberCount;
  31.         double p2Part = (double) p2/numberCount;
  32.         double p3Part = (double) p3/numberCount;
  33.         double p4Part = (double) p4/numberCount;
  34.         double p5Part = (double) p5/numberCount;
  35.        
  36.         System.out.printf("%.2f%% \n", p1Part * 100);
  37.         System.out.printf("%.2f%% \n", p2Part * 100);
  38.         System.out.printf("%.2f%% \n", p3Part * 100);
  39.         System.out.printf("%.2f%% \n", p4Part * 100);
  40.         System.out.printf("%.2f%% \n", p5Part * 100);
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement