Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class HistogramExerciseTask5 {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int n = Integer.parseInt(scanner.nextLine());
- int counterP1 = 0;
- int counterP2 = 0;
- int counterP3 = 0;
- int counterP4 = 0;
- int counterP5 = 0;
- int counterP = 0;
- for (int i = 1; i <= n; i++) {
- int curentNum = Integer.parseInt(scanner.nextLine());
- if (curentNum < 200) {
- counterP1++;
- } else if (curentNum < 400) {
- counterP2++;
- } else if (curentNum < 600) {
- counterP3++;
- } else if (curentNum < 800) {
- counterP4++;
- } else if (curentNum <= 1000) {
- counterP5++;
- }
- counterP++;
- }
- /*double percentP1 = counterP1 / 20 * 100;
- double percentP2 = counterP2 / 20 * 100;
- double percentP3 = counterP3 / 20 * 100;
- double percentP4 = counterP4 / 20 * 100;
- double percentP5 = counterP5 / 20 * 100;*/
- double totalPercent = 100;
- double partsPercet = totalPercent / counterP;
- double percentP1 = counterP1 * partsPercet;
- double percentP2 = counterP2 * partsPercet;
- double percentP3 = counterP3 * partsPercet;
- double percentP4 = counterP4 * partsPercet;
- double percentP5 = counterP5 * partsPercet;
- System.out.printf("%.2f%%%n%.2f%%%n%.2f%%%n%.2f%%%n%.2f%%", percentP1, percentP2, percentP3, percentP4, percentP5);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement