Ask Question
17 April, 01:46

Design and implement an application that reads an arbitrary number of integers that are in the range 0 to 50 inclusive and counts how many occurrences of each are entered. After all input has been processed, print all of the values (with the number of occurrences) that were entered one or more times. The output should be one frequency count per line with the following format: 3 occurrences of 2 7 occurrences of 5

+1
Answers (1)
  1. 17 April, 03:14
    0
    import java. util. Scanner; public class Main { public static void main (String[] args) { int numArr [] = new int[51]; int num; Scanner input = new Scanner (System. in); do{ System. out. print ("Input number between 0 - 50: "); num = input. nextInt (); if (num > = 0 && num < = 50) { numArr[num]++; } }while (num! = - 1); for (int i=0; i 0) { System. out. println (numArr[i] + " occurrences of " + i); } } } }

    Explanation:

    The solution code is written in Java.

    Firstly, create a numArr array with 51 elements (Line 6).

    Next, use do while loop to repeatedly prompt user for an input number between 0 - 50. If num is between 0 - 50, use the input number as index to increment that particular element of array by one (Line 10 - 15).

    At last, create another for-loop to traverse through the numArr array and print all the elements with value at least one (Line 18 - 21).
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Design and implement an application that reads an arbitrary number of integers that are in the range 0 to 50 inclusive and counts how many ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers