Ask Question
23 November, 10:02

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

+2
Answers (1)
  1. 23 November, 10:09
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers