In the printArray function, I am trying to print the whole array to one JOptionPane box, but it is printing each individual number to a different box. Could someone please help me figure this out.
Thank You,
webmasterj04
import java.util.Arrays;
import javax.swing.JOptionPane;
public class Lotto
{
public static void main(String[] args)
{
JOptionPane.showMessageDialog(null,"WELCOME TO THE LOTTO PROGRAM");
int size = 6;
int [] lottoArray = {0,0,0,0,0,0};
int [] userArray = {0,0,0,0,0,0};
//======Part 1========\\
JOptionPane.showMessageDialog(null,"Part 1 of The Lotto");
fillArrayPt1(lottoArray, size);
Arrays.sort(lottoArray);
printArray(lottoArray, size);
//======Part 2========\\
JOptionPane.showMessageDialog(null,"Part 2 of The Lotto");
fillArrayPt2(userArray, size);
Arrays.sort(userArray);
printArray(userArray, size);
//compareArrays(lottoArray, userArray, size);
}//main
public static void printArray(int [] printArray, int s)
{
for(int x=0; x<printArray.length; x++)
{
JOptionPane.showMessageDialog(null,printArray[x] + " ");
}
}//printArray
//***********Part 1***************\\
public static void fillArrayPt1(int [] a, int s)
{
int [] testArray = new int[54];
int randNum;
for(int x=0; x<54; x++)
{
testArray[x] = 0;
}
for (int x=0; x<s; x++)
{
randNum = (int)(Math.random() *53) +1;
while(testArray[randNum]== 1)
{
randNum = (int)(Math.random() *53) +1;
}
a[x] = randNum;
testArray[randNum] = 1;
}
}//fillArrayPt1
//*******Part 2**********\\
public static void fillArrayPt2(int [] a, int s)
{
String pickNum = "1";
String quickPick = "2";
String ans;
String StrNum1, StrNum2, StrNum3, StrNum4, StrNum5, StrNum6;
ans = JOptionPane.showInputDialog(null,"1: Pick your own six numbers. \n2: Have six quick picks.\n Choice Option 1 or 2");
if (ans.equals(pickNum))
{
JOptionPane.showMessageDialog(null,"Please enter 6 differnt numbers ranging from 1 to 53.");
int choice = 1;
while(choice < 6)
{
for(int x=0; x<s; x++)
{
String StrNum;
StrNum = JOptionPane.showInputDialog(null, "Enter number " + choice);
++choice;
int num = Integer.parseInt(StrNum);
a[x] = num;
}
}
}
else if (ans.equals(quickPick))
{
JOptionPane.showMessageDialog(null,"Your quick picks numbers are as follows.");
int [] testArray = new int[54];
int randNum;
for(int x=0; x<54; x++)
{
testArray[x] = 0;
}
for (int x=0; x<s; x++)
{
randNum = (int)(Math.random() *53) +1;
while(testArray[randNum]== 1)
{
randNum = (int)(Math.random() *53) +1;
}
a[x] = randNum;
testArray[randNum] = 1;
}
}
else
JOptionPane.showMessageDialog(null,"ERROR! Please try again!");
}//fillArrayPt2
public static void compareArrays(int [] a, int s)
{
}//compareArrays
}//class Lotto
Message was edited by: webmasterj04