Advertisement
MoPhreak

Untitled

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