Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package S4_ForLoops;
- 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());
- // define counters for each diapason
- int p1Count = 0;
- int p2Count = 0;
- int p3Count = 0;
- int p4Count = 0;
- int p5Count = 0;
- for (int i = 0; i < n; i++) {
- int number = Integer.parseInt(scanner.nextLine());
- // check for defined diapason and save count for each
- if (number < 200) {
- // p1Count = p1Count + 1;
- // p1Count += 1;
- p1Count++;
- } else if(number <= 399) {
- p2Count++;
- } else if(number <= 599) {
- p3Count++;
- } else if(number <= 799) {
- p4Count++;
- } else {
- p5Count++;
- }
- }
- System.out.printf("%.2f%%%n", 1.0 * p1Count/n * 100);
- System.out.printf("%.2f%%%n", 1.0 * p2Count/n * 100);
- System.out.printf("%.2f%%%n", 1.0 * p3Count/n * 100);
- System.out.printf("%.2f%%%n", 1.0 * p4Count/n * 100);
- System.out.printf("%.2f%%", 1.0 * p5Count/n * 100);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement