Okay I am making this program and I have everything down except the last part to display the results. Here's what I have so far. THe error (in red) is that it can't find symbol : JOptionPane
The program generates 100 random integers between 0 and 9 and should display the # of each occurence.
Code:
public class CountingSingleDigits {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// Declare and create and array
int[] ints = createArray();
// Count occurence of each number
int[] counts = countLetters(ints);
// Call display result
displayCounts(counts);
}
public static int[] createArray() {
int[] ints = new int[100]; //make new array to hold 100 ints.
for (int i = 0; i < ints.length; i++)
ints[i] = (int)(Math.random() * 10); //generate 100 random ints
return ints; //between 0 and 9
}
public static int[] countLetters(int[] ints) {
int[] counts = new int[10]; //make new array to store occurences
for (int i = 0; i < ints.length; i++) //count how many occurences
counts[ints[i] - 0]++ ;
return counts;
}
// Display results
public static void displayCounts(int[] counts) {
for (int i = 0; i< counts.length; i++)
JOptionPane.showMessageDialog(counts[i] + (i + 0) + "\n"
, JOptionPane.INFORMATION_MESSAGE);
}
}