Advertisement
Guest User

Untitled

a guest
Feb 17th, 2019
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class HistogramExerciseTask5 {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6.  
  7. int n = Integer.parseInt(scanner.nextLine());
  8. int counterP1 = 0;
  9. int counterP2 = 0;
  10. int counterP3 = 0;
  11. int counterP4 = 0;
  12. int counterP5 = 0;
  13. int counterP = 0;
  14.  
  15.  
  16. for (int i = 1; i <= n; i++) {
  17. int curentNum = Integer.parseInt(scanner.nextLine());
  18.  
  19. if (curentNum < 200) {
  20. counterP1++;
  21. } else if (curentNum < 400) {
  22. counterP2++;
  23. } else if (curentNum < 600) {
  24. counterP3++;
  25. } else if (curentNum < 800) {
  26. counterP4++;
  27. } else if (curentNum <= 1000) {
  28. counterP5++;
  29. }
  30. counterP++;
  31. }
  32. /*double percentP1 = counterP1 / 20 * 100;
  33. double percentP2 = counterP2 / 20 * 100;
  34. double percentP3 = counterP3 / 20 * 100;
  35. double percentP4 = counterP4 / 20 * 100;
  36. double percentP5 = counterP5 / 20 * 100;*/
  37.  
  38. double totalPercent = 100;
  39. double partsPercet = totalPercent / counterP;
  40. double percentP1 = counterP1 * partsPercet;
  41. double percentP2 = counterP2 * partsPercet;
  42. double percentP3 = counterP3 * partsPercet;
  43. double percentP4 = counterP4 * partsPercet;
  44. double percentP5 = counterP5 * partsPercet;
  45. System.out.printf("%.2f%%%n%.2f%%%n%.2f%%%n%.2f%%%n%.2f%%", percentP1, percentP2, percentP3, percentP4, percentP5);
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement