Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import javax.swing.JOptionPane; // I used JOption, you can set it to command line if thats what you currently use.
- public class RandomClassTest
- {
- public static void main(String[] args)
- {
- Random randNumGenerator = new Random();
- int[] randomNumberArray = new int[4];
- String[] enteredUserNumberArray = new String[4];
- int[] actualUserNumberArray = new int[4];
- int reward = 0;
- for (int i=0; i<enteredUserNumberArray.length; i++) // Populates the user number array with 4 numbers.
- {
- enteredUserNumberArray[i] = JOptionPane.showInputDialog(null, "Number?"); // Will be asked four times to populate the array indexes.
- for (int j=0; j<actualUserNumberArray.length; j++)
- {
- actualUserNumberArray[j] = Integer.parseInt(enteredUserNumberArray[i]);
- }
- }
- for (int i=0; i<randomNumberArray.length; i++) //Populates the lottery random number array with 4 random numbers between 1-10.
- {
- randomNumberArray[i] = (randNumGenerator.nextInt(10)+1);
- }
- for (int i=0; i<actualUserNumberArray.length; i++)
- {
- for(int j=0; j<randomNumberArray.length; j++)
- {
- if (actualUserNumberArray[i] == (randomNumberArray[j]))
- {
- reward = reward + 1;
- }
- }
- }
- JOptionPane.showMessageDialog(null, "The numbers you entered were " + enteredUserNumberArray + ", the numbers in the lottery were: " + randomNumberArray + ", you managed to win €" + reward);
- System.exit(0);
- }
- }
Add Comment
Please, Sign In to add comment