public class Lotto {
private static int[] num = null;
private int getNum(){
return (int)(Math.random()*45) + 1;
}
private void lottery(){
num = new int[7];
for(int i=1; i<=6; i++){
num[i] = this.getNum();
for(int j=1; j<=i; j++){
//System.out.println(" : "+j+" : ");
if(i != j && num[i] == num[j]){
num[i] = this.getNum();
//System.out.println(" 중복발견 ");
j -= 1;
}
}
}
}
private void show(){
for(int i=1; i<=6; i++){
try {
Thread.sleep(1500); // 0.001초 단위
System.out.print(num[i]+" ");
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
private void sort(){
int location = 0;
int min = 0;
for (int i=1; i<num.length; i++){
min = num[i];
//SelectionSort 최소값 구하기
for(int j=i; j<num.length; j++){
if (min > num[j]){
min = num[j];
//최소값의 배열 위치 기억
location = j;
}
} //inner for
if (min != num[i]){
num[location] = num[i];
num[i] = min;
}
}// for
}
private void initialize(){
this.lottery();
this.sort();
this.show();
}
public static void main(String[] args) {
Lotto lt = new Lotto();
lt.initialize();
}
}
1. 최소값으로 정렬
2. 중복값 발견시 다시 번호 갖고 오기
좀 아쉬운 부분이 있을까요? ㅋㅋ
첫댓글 많이 아쉬워 ~!!! ㅋㅋㅋㅋ 뻥이고 왜 올린거냐? ㅋ
이제서야 확인일 했네요~~ ㅠㅠ