카테고리 없음

로또번호 생성 프로그램

코딩딩 2016. 3. 22. 14:10

로또번호 생성 프로그램


※ 프로그램의 조건

1. 번호가 중복되지 않는다.
2. 6개의 숫자 선택

JAVA 코드

public class Lotto {

public static void main(String[] args) {

int[] selNum = new int[6]; //배열 만들기

for (int i = 0; i < selNum.length; i++){

selNum[i]= (int)(Math.random()*45+1);

for (int j = 0; j < i; j++){

if (selNum[i] == selNum[j]){

i--; // for문 전단계로 이동하기 위해 임의로 1빼기

continue;

}

}

}

for (int value : selNum)

System.out.println(value);

}

}