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());
- double p1 = 0;
- double p2 = 0;
- double p3 = 0;
- double p4 = 0;
- double p5 = 0;
- double total = 0;
- for (int i = 0; i <n ; i++) {
- int num = Integer.parseInt(scanner.nextLine());
- if (num < 200) {
- p1 += 1;
- } else if ((200 <= num) &&(num <=399)) {
- p2 += 1;
- } else if ((400<=num) && (num<=599)){
- p3 +=1;
- } else if ((600<=num) && (num<=799)){
- p4+=1;
- } else if (num>=800){
- p5+=1;
- }
- }
- total = p1 + p2 + p3 + p4 + p5;
- p1 = (p1/total)*100;
- p2 = (p2/total)*100;
- p3 = (p3/total)*100;
- p4 = (p4/total)*100;
- p5 = (p5/total)*100;
- System.out.printf("%.2f%%%n", p1);
- System.out.printf("%.2f%%%n", p2);
- System.out.printf("%.2f%%%n", p3);
- System.out.printf("%.2f%%%n", p4);
- System.out.printf("%.2f%%%n", p5);
- }
- }
Add Comment
Please, Sign In to add comment