I know how to get the input for the array and store and then display the numbers
ID: 3674761 • Letter: I
Question
I know how to get the input for the array and store and then display the numbers, but I can't figure out how to display how many times each number was called. Java. Write a program that reads an arbitrary number of integer that are in the range 0 - 50 inclusive and counts how many occurrences of each are entered. Indicate the end of the input by a value outside of the range. After all input has been processed, print all of the values (with the number of occurences) that were entered one or more timesJ
Explanation / Answer
import java.util.Scanner; public class CountInts{ public static void main (String[] args){ int[] count = new int[51]; // new array indexed from 0 to 50 // initialized to contain all 0’s Scanner scan = new Scanner (System.in); System.out.print("Enter integers, ending with D: "); while (scan.hasNext()){ int n = scan.nextInt(); if (n>=0 && nRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.