로또 중복안되게...짜증나네
package Array;
import java.util.Random;
public class Program {
public static void main(String[] args) {
Random rand = new Random(); // 랜덤 함수
int[] Lotto = new int[6]; // 배열 선언
for (int i = 0; i < Lotto.length; i++) {
int A=rand.nextInt(45) + 1; // 배열선언시 0부터 시작하므로 +1
for(int j=0;j<Lotto.length;j++){
if(A==Lotto[j]){
A=rand.nextInt(45) + 1; // 배열선언시 0부터 시작하므로 +1
j = -1; //j++ 값을 상쇄시켜주기 위해(증감을 막음. 비교하기 위해서)
}
}
Lotto[i]=A;
System.out.printf("%d ", Lotto[i]); // 로또 랜덤 6개 출력
}
System.out.println(); // 띄어쓰기 프린트
for (int i = 0; i < 6; i++) {
for (int k = i + 1; k < 6; k++) {
if (Lotto[i] > Lotto[k]) { // 두수를 비교해서 i값이 크다면
int temp;
temp = Lotto[i];
Lotto[i] = Lotto[k];
Lotto[k] = temp; // 큰숫자를 뒤로 보낸다
}
}
System.out.printf("%d ", Lotto[i]);
}
}
}