Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Histogram {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int n = Integer.parseInt(scanner.nextLine());
- int p = 0;
- double p1 = 0;
- double p2 = 0;
- double p3 = 0;
- double p4 = 0;
- double p5 = 0;
- double percent = 0;
- for (int i = 0; i < n; i++) {
- p = Integer.parseInt(scanner.nextLine());
- if (p < 200) {
- p1++;
- } else if (p >= 200 && p <= 399) {
- p2++;
- } else if (p >= 400 && p <= 599) {
- p3++;
- } else if (p >= 600 && p <= 799) {
- p4++;
- } else if (p >= 800 && p <= 1000) {
- p5++;
- }
- }
- System.out.printf("%.2f%%%n", p1 / n * 100);
- System.out.printf("%.2f%%%n", p2 / n * 100);
- System.out.printf("%.2f%%%n", p3 / n * 100);
- System.out.printf("%.2f%%%n", p4 / n * 100);
- System.out.printf("%.2f%%%n", p5 / n * 100);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement