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 scan = new Scanner(System.in);
- int n = Integer.parseInt(scan.nextLine());
- double p1 = 0, p2 = 0, p3 = 0, p4 = 0, p5 = 0;
- for (int i = 0; i < n; i++) {
- double number = Double.parseDouble(scan.nextLine());
- if(number < 200){
- p1++;
- }
- else if(number >= 200 && number < 400){
- p2++;
- }
- else if(number >= 400 && number < 600){
- p3++;
- }
- else if(number >= 600 && number < 800){
- p4++;
- }
- else if(number >= 800){
- p5++;
- }
- }
- p1 = p1 / n * 100;
- p2 = p2 / n * 100;
- p3 = p3 / n * 100;
- p4 = p4 / n * 100;
- p5 = p5 / n * 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);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement