Advertisement
Ivakis

Хистограма

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