Advertisement
veronikaaa86

03. Histogram

Jan 30th, 2022
424
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. package forLoop;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class P03Histogram {
  6. public static void main(String[] args) {
  7. Scanner scanner = new Scanner(System.in);
  8.  
  9. int n = Integer.parseInt(scanner.nextLine()); //5
  10.  
  11. int p1 = 0;
  12. int p2 = 0;
  13. int p3 = 0;
  14. int p4 = 0;
  15. int p5 = 0;
  16. for (int i = 1; i <= n; i++) {
  17. int currentNum = Integer.parseInt(scanner.nextLine());
  18.  
  19. if (currentNum < 200) {
  20. p1++;
  21. } else if (currentNum <= 399) {
  22. p2++;
  23. } else if (currentNum <= 599) {
  24. p3++;
  25. } else if (currentNum <= 799) {
  26. p4++;
  27. } else {
  28. p5++;
  29. }
  30. }
  31.  
  32. System.out.printf("%.2f%%%n", p1 * 1.0 / n * 100);
  33. System.out.printf("%.2f%%%n", p2 * 1.0 / n * 100);
  34. System.out.printf("%.2f%%%n", p3 * 1.0 / n * 100);
  35. System.out.printf("%.2f%%%n", p4 * 1.0 / n * 100);
  36. System.out.printf("%.2f%%%n", p5 * 1.0 / n * 100);
  37. }
  38. }
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement