I'm working on a simple matching game, whereby my array includes 3 numbers:{ 5,9,0 } and the user tries to guess them.
Instead, I want to use the Random class to generate 3 different numbers from 0-9, but I'm not sure how or where to start. I came across info on the Random class; however, there are no good examples using it with arrays. But, then I'm awful at arrays and need improvement in this area.
Can anyone help me out in this area? Thanks in advance.
import java.io.*;
import javax.swing.JOptionPane;
public class MatchGame
{
public static int[] guess = {5,9,0};
public static void main(String[] args) throws IOException
{
MatchGame();
}
public static void MatchGame()
{
int o = 3;
boolean arraysMatch = true;
String input;
int i = 0;
int[] x = new int[o];
for (i = 0; i < o; i++)
{
input = JOptionPane.showInputDialog("Input your 3 guesses: "+ (i + 1));
x[i] = Integer.parseInt(input);
}
i = 0;
if (guess.length != x.length)
arraysMatch = false;
while (arraysMatch && i < guess.length)
{
if (guess[i] != x[i])
arraysMatch = false;
i++;
}
if (arraysMatch)
JOptionPane.showMessageDialog(null, "Hooray! You matched all 3 numbers.");
else
JOptionPane.showMessageDialog(null, "Sorry, you didn't match!");
results();
}
public static void results()
{
JOptionPane.showMessageDialog(null, "The Correct Numbers: " + guess[0] +
guess[1] + guess[2]);
}
}