Untitled

 avatar
unknown
java
2 years ago
2.2 kB
4
Indexable
import java.util.*;

import javax.swing.plaf.synth.SynthEditorPaneUI;
import javax.swing.text.StyledEditorKit;

public class a {

	public static void main(String[] args) {
		// TODO Auto-generated method stub

		int[] lotto=new int[46];
		int[] lotto_target =new int[6];
		Scanner sc = new Scanner((System.in));
		int row_cnt= sc.nextInt();

		System.out.println("[로또 당첨 프로그램]");
		System.out.println("로또 개수를 입력해 주세요.(숫자 1~10): "+row_cnt);
	
		int[][] myLottos=new int[row_cnt][6];
        for(int i = 0;i<row_cnt;i++){ // row 
            int num_cnt = 0;
            while(num_cnt<6){
                int tmp = (int)(1+45*Math.random());
                if(lotto[tmp]==0){
                    lotto[tmp] = 1;
                    myLottos[i][num_cnt] = tmp;
                    num_cnt++;
                }else{
                    continue;
                }
            }
            for(int l = 0; l<6;l++){
                lotto[myLottos[i][l]] = 0;
            }
        }

        int cnt = 0;
        while(cnt<6){
            int tmp = (int)(1+45*Math.random());
            if(lotto[tmp]==0){
                lotto[tmp] = 1;
                lotto_target[cnt] = tmp;
                cnt+=1;

            }
            else{
                continue;
            }
        }

        System.out.println("-------------------");
        
        System.out.println("로또 번호 : ");
        Arrays.sort(lotto_target);
        for(int i =0;i<6;i++){
            System.out.print((i+1)+"번 : "+ lotto_target[i] + " ");
        }
        System.out.println();

        for(int i = 0;i<row_cnt;i++){
            Arrays.sort(myLottos[i]);
            int chk_cnt = 0;
            System.out.print((i+1) + "th lotto nums : ");
            for(int j = 0;j<6;j++){
                if(myLottos[i][j] == lotto_target[j]){
                    chk_cnt++;
                }
                System.out.print(myLottos[i][j]+" ");
             
            }
            System.out.println();
            System.out.println((i+1) + "번쨰 일치하는 로또개수 : " + chk_cnt);
        }

        sc.close();
    }
}
Editor is loading...