Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Use at least two methods in the program. Use an array parameter in a method that

ID: 3633337 • Letter: U

Question

Use at least two methods in the program.
Use an array parameter in a method that assigns values to the array.

Write a program that reads a list of up to 50 integer values that are between 0 and 100 into an array.
The program outputs a list of each unique value entered followed by the frequency of the number of times it occurred
For example: if you enter: 51 49 51 48 51 49 47
Sample output:0 occurs 0 times

47 occurs 1 times
48 occurs 1 times
49 occurs 2 times
51 occurs 3 times

100 occurs 0 times

Explanation / Answer

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class FreqCount
{
   public static void main(String[] args) throws NumberFormatException, IOException
   {
       final int MAX_NUM_COUNT = 50;
       int[] inputs = new int[MAX_NUM_COUNT];
       InputStreamReader inp = new InputStreamReader(System.in);
       BufferedReader input=new BufferedReader(inp);
       int nCount = 1;
       while(nCount <= MAX_NUM_COUNT)
       {
           System.out.println("Enter number#"+nCount+" >>");
           int tmp = Integer.parseInt(input.readLine());
           if(tmp >= 0 && tmp <= 100)
           {
               inputs[nCount-1] = tmp;
               nCount++;
           }
           else
           {
               System.out.println("Error: Input should be in between 0-100.Please try again...");
           }
       }
       for(int j=0;j<=100;j++)
       {
           int tmpcount = 0;
           for(int i=0;i<MAX_NUM_COUNT;i++)
           {
               if(inputs[i] == j)
               {
                   tmpcount++;
               }
           }
           System.out.println(j+" occurs "+tmpcount+" times");
       }
   }
}