반응형
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | import java.util.Scanner; public class Lotto_Machine { static int[] lotto_win = new int[6]; static int game = 0; static int[] lotto() { // 추첨 int tong; System.out.println(); System.out.print("당첨번호 :" + "\t"); for (int i = 0; i < 6; i++) { lotto_win[i] = (int) (Math.random() * 45) + 1; for (int a = 0; a < i; a++) { // 중복값 if (lotto_win[a] == lotto_win[i]) { lotto_win[i] = (int) (Math.random() * 45) + 1; } } } for (int i = 1; i < 6; i++) { // 당첨번호 오름차순 for (int j = 0; j < 6; j++) { if (lotto_win[j] > lotto_win[i]) { tong = lotto_win[j]; lotto_win[j] = lotto_win[i]; lotto_win[i] = tong; } } } // 오름차순 출력 for (int i = 0; i < 6; i++) { System.out.print(lotto_win[i] + "\t"); } System.out.println(); System.out.println("-------------------------------------------------------------"); return lotto_win; } static void lotto_result(int[][] game_number, int[] win) { // 등수 int count = 0; for (int ii = 0; ii < game; ii++) { System.out.print(ii + 1 + "번째 맞은 갯수 : "); for (int i = 0; i < 6; i++) { for (int j = 0; j < 6; j++) { if (game_number[ii][i] == win[j]) { count++; } } if (i == 5) { System.out.print(count); switch (count) { case 6: System.out.print(" 1등 당첨!!!"); break; case 5: System.out.print(" 2등 당첨!!"); break; case 4: System.out.print(" 3등 당첨!"); break; default: System.out.println(" ...꽝..."); break; } } } System.out.println(); count = 0; } } public static void main(String[] args) { System.out.println("몇 게임 하시겠습니까?"); Scanner s = new Scanner(System.in); game = s.nextInt(); int[][] game_number = new int[game][6]; for (int i = 0; i < game; i++) { for (int j = 0; j < 6; j++) { game_number[i][j] = (int) (Math.random() * 45) + 1; for (int a = 0; a < j; a++) { // 중복값 if (game_number[i][a] == game_number[i][j]) { game_number[i][j] = (int) (Math.random() * 45) + 1; } } } } int tong; for (int ii = 0; ii < game; ii++) { for (int i = 1; i < 6; i++) { for (int j = 0; j < 6; j++) { if (game_number[ii][j] > game_number[ii][i]) { tong = game_number[ii][j]; game_number[ii][j] = game_number[ii][i]; game_number[ii][i] = tong; } } } } for (int j = 0; j < game; j++) { System.out.print(j + 1 + "번째 게임 :" + "\t"); for (int i = 0; i < 6; i++) { System.out.print(game_number[j][i] + "\t"); } System.out.println(); } System.out.println("-------------------------------------------------------------"); System.out.println("당첨번호는....3초후 공개합니다."); try { Thread.sleep(3000); System.out.println("-------------------------------------------------------------"); } catch (Exception e) { } lotto(); // 이번주 당첨번호 lotto_result(game_number, lotto_win); // 오름차순정렬 및 등수 } } |
반응형
'(Before)BitSchool' 카테고리의 다른 글
2014/5/15 데이터베이스 - 오라클 (0) | 2014.05.15 |
---|---|
2014/5/14 데이터베이스 - Oracle (0) | 2014.05.14 |
2014/05/13 Java - Abstract추상클래스, interface 인터페이스, final, 예외처리, try, catch, throws (0) | 2014.05.13 |
2014/5/12 Java - this,상속, 다형성 (0) | 2014.05.12 |
2014/5/9 java 객체지향, class, static (0) | 2014.05.09 |