paykova

Histogram

Oct 13th, 2017
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 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.  
  7. int n = Integer.parseInt(scanner.nextLine());
  8. double p1 = 0;
  9. double p2 = 0;
  10. double p3 = 0;
  11. double p4 = 0;
  12. double p5 = 0;
  13. double total = 0;
  14.  
  15. for (int i = 0; i <n ; i++) {
  16. int num = Integer.parseInt(scanner.nextLine());
  17.  
  18. if (num < 200) {
  19. p1 += 1;
  20. } else if ((200 <= num) &&(num <=399)) {
  21. p2 += 1;
  22. } else if ((400<=num) && (num<=599)){
  23. p3 +=1;
  24. } else if ((600<=num) && (num<=799)){
  25. p4+=1;
  26. } else if (num>=800){
  27. p5+=1;
  28. }
  29. }
  30. total = p1 + p2 + p3 + p4 + p5;
  31. p1 = (p1/total)*100;
  32. p2 = (p2/total)*100;
  33. p3 = (p3/total)*100;
  34. p4 = (p4/total)*100;
  35. p5 = (p5/total)*100;
  36. System.out.printf("%.2f%%%n", p1);
  37. System.out.printf("%.2f%%%n", p2);
  38. System.out.printf("%.2f%%%n", p3);
  39. System.out.printf("%.2f%%%n", p4);
  40. System.out.printf("%.2f%%%n", p5);
  41. }
  42. }
Add Comment
Please, Sign In to add comment