Advertisement
GabrielHr00

03. Histogram

Jun 4th, 2023
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.06 KB | None | 0 0
  1. package S4_FoorLoops;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Histogram {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.         int n = Integer.parseInt(scanner.nextLine());
  9.  
  10.         int p1 = 0;
  11.         int p2 = 0;
  12.         int p3 = 0;
  13.         int p4 = 0;
  14.         int p5 = 0;
  15.  
  16.         for (int i = 1; i <= n; i++) {
  17.             int digit = Integer.parseInt(scanner.nextLine());
  18.  
  19.             if (digit < 200) {
  20.                 p1++;
  21.             } else if (digit <= 399) {
  22.                 p2++;
  23.             } else if (digit <= 599) {
  24.                 p3++;
  25.             } else if (digit <= 799) {
  26.                 p4++;
  27.             } else if (digit >= 800) {
  28.                 p5++;
  29.             }
  30.         }
  31.  
  32.  
  33.         System.out.printf("%.2f%%%n", (1.0 * p1) / n * 100);
  34.         System.out.printf("%.2f%%%n", 1.0*p2/n * 100);
  35.         System.out.printf("%.2f%%%n", 1.0*p3/n * 100);
  36.         System.out.printf("%.2f%%%n", 1.0*p4/n * 100);
  37.         System.out.printf("%.2f%%%n", 1.0*p5/n * 100);
  38.  
  39.     }
  40. }
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement