I know how to create the array as i did below. But how would i check if the user inputed the same number. I tried using if statements but i kept getting errors. I also tried using a do while.
I have to write a program that generates and stores 20 random numbers in the array Data[]
and asks the user to enter their guess which i did. If their number appears in the array, they get 2 points for each occurrence, the array is printed and all positions where the lucky number can be found. If it doesn't appear in the array, I have to print the lowest and highest values of the array and allow only one more try. if the player gets it right the second time they get 1 point for each appearance.
int lucky;
int Data[]= new int[20];
for(int i=0;i<Data.length;i++){
Data[i]=(int)(Math.random()*100);
}
for(int i=0;i<Data.length;++i){
System.out.println(Data[i]+"\t");
}
String input1=JOptionPane.showInputDialog("Enter your lucky number");
lucky=Integer.parseInt(input1);
System.out.println(lucky);