borkins

Exam 06-Mar-2016 - 04. Histogram

May 14th, 2017
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.79 KB | None | 0 0
  1. /**
  2.  * Project: Exam_06_March_2016 - created by borkins on 2017-05-14.
  3.  */
  4.  
  5. import java.util.Scanner;
  6.  
  7. public class _04_Histogram
  8. {
  9.     public static void main(String[] args)
  10.     {
  11.         Scanner console = new Scanner(System.in);
  12.    
  13.         int n = Integer.parseInt(console.nextLine());
  14.    
  15.         int[] p = new int[5];
  16.    
  17.         for (int i = 0; i < n; i++)
  18.         {
  19.             int num = Integer.parseInt(console.nextLine());
  20.        
  21.             if (num < 200) p[0]++;
  22.             else if (num < 400) p[1]++;
  23.             else if (num < 600) p[2]++;
  24.             else if (num < 800) p[3]++;
  25.             else p[4]++;
  26.         }
  27.    
  28.         for (int i = 0; i < p.length; i++)
  29.         {
  30.             System.out.printf("%.2f%%%n", (p[i] / (double) n * 100));
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment