package lotto;
import java.util.Random;
public class Lotto {
/**
* * @param args
*/
public static void main(String[] args) {
// // TODO Auto-generated method stub
//Get a lotto array.
Lotto lotto = new Lotto();
int[] lottoArray = lotto.lottoNumGenerator();
//print the lotto number.
System.out.println ("==lotto number==");
for(int i=0;i<lottoArray.length;i++){
System.out.print(lottoArray[i]+" ");
}
}
int[] lottoNumGenerator(){
//Create an array to store six numeric variables.
int lottoNumbers[] = new int[6];
//Use Random to generate random numbers from 1 to 45 and store them in an array.
Random random = new Random();
for(int i =0;i<lottoNumbers.length;i++){
lottoNumbers[i]=random.nextInt(45)+1;
}
// Double check of random numbers in the array, reset the value.
boolean duplication = true;
for(int i =0;i<lottoNumbers.length;i++){
for(int j=0;j<lottoNumbers.length;j++){
if(i!=j&&lottoNumbers[i]==lottoNumbers[j]){
duplication=true;
lottoNumbers[i]=random.nextInt(45)+1;
break;
}else{
duplication=false;
}
}
//to reset indefinitely until the number of duplicates is changed i--
if(duplication){
i--;
}
}
return lottoNumbers;
}
}
There are conditions like this. I think number 1 has been solved, so where and what should I add to do the other two or three?
java source
How about creating a class called LottoPool as follows?
Member variable: Create a list called pickedNumber as public.
Method
615 GDB gets version error when attempting to debug with the Presense SDK (IDE)
577 Who developed the "avformat-59.dll" that comes with FFmpeg?
925 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
624 Uncaught (inpromise) Error on Electron: An object could not be cloned
© 2024 OneMinuteCode. All rights reserved.