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

Write a program called CountOccurrences that asks a user to enter ten integers b

ID: 645488 • Letter: W

Question

Write a program called CountOccurrences that asks a user to enter ten integers between 1 and 100. Your program will store the integers into an array and then count the occurrences of each number in the array.

Design the main() method of your program such that it allows the user to re-run the program with different inputs (i.e., use a loop structure).

Here is a sample output:

Explanation / Answer

import java.util.Scanner; public class countNumberOccurrence{ public static void main(String args[]){ int[] numbers = new int[100]; inputArray(numbers); } public static void inputArray(int[] myList){ Scanner input = new Scanner(System.in); System.out.print("Enter integers from 1-100 (input 0 value to end inputs): "); int index = 0; for(int i = 1; i 0){ index = input.nextInt(); if (index > 0 && index 1) System.out.println(index + " occurs " + myList[index-1] + " times "); else System.out.println(index + " occurs " + myList[index-1] + " time "); } } }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote