Write a public class call CountInts. class CountInts has a main method. CountInts must have two methods:...

50.1K

Verified Solution

Question

Programming

Write a public class call CountInts.class CountInts has a main method.CountInts must have two methods: count and displayResults.1. method count takes an array, aa, of ints and counts how many timeseach integer appears in aa. The integers can only be from 0 to 100inclusive.2. method display results displays the results of the count3. use the template provided. insert your code in the placesindicated and don't change anything else.

Examples

% java CountInts 0 1 2 3 4 5 2 3 4 5 4 5 5 [0,1, 2, 3, 4, 5, 2, 3, 4, 5, 4, 5, 5] 0 occurs ONE time 1 occurs ONEtime 2 occurs 2 times 3 occurs 2 times 4 occurs 3 times 5 occurs 4times % java CountInts 0 1 2 1000 -3 2 [0, 1, 2,1000, -3, 2] 0 occurs ONE time 1 occurs ONE time 2 occurs 2times

Template:

import java.util.*;

public class CountInts {

public static void count(int [] aa){

/*insert your code here */

}

public static void displayResults(){

/*insert your code here */

}

public static int [] readArray(){

Scanner input = new Scanner(System.in);

String ss = input.nextLine();

String [] aa = ss.split(\"[, ]\");

if(aa[0].length() == 0)

aa = new String[0];

//System.out.println(Arrays.toString(aa));

int [] dd = new int[aa.length];

int ii = 0;

for(String s : aa){

dd[ii++] = Integer.parseInt(s);

}

return dd;

}

public static void main (String[] args) {

int [] arr = readArray();

System.out.println(Arrays.toString(arr));

count(arr);

displayResults();

}

}

Answer & Explanation Solved by verified expert
4.0 Ratings (761 Votes)
Here is the completed code for this problem Comments are included go through it learn how things work and let me know if you have any doubts or if you need anything to change If you are satisfied with    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students