Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Histogram {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6. int n = Integer.parseInt(scanner.nextLine());
  7. int counterP1 = 0;
  8. int counterP2 = 0;
  9. int counterP3 = 0;
  10. int counterP4 = 0;
  11. int counterP5 = 0;
  12.  
  13. for (int i = 1; i <= n; i++) {
  14. int num = Integer.parseInt(scanner.nextLine());
  15.  
  16. if (num >= 800) {
  17. counterP5++;
  18. } else if (num >= 600) {
  19. counterP4++;
  20. } else if (num >= 400) {
  21. counterP3++;
  22. } else if (num >= 200) {
  23. counterP2++;
  24. } else {
  25. counterP1++;
  26. }
  27. }
  28. System.out.printf("%.2f%%%n", (double) counterP1 / n * 100);
  29. System.out.printf("%.2f%%%n", (double) counterP2 / n * 100);
  30. System.out.printf("%.2f%%%n", (double) counterP3 / n * 100);
  31. System.out.printf("%.2f%%%n", (double) counterP4 / n * 100);
  32. System.out.printf("%.2f%%%n", (double) counterP5 / n * 100);
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement