10947번 - 로또
자바로 작성하였습니다. 계속 틀렸다고 나와서 그러는데 어디가 문제인가요
public class Main { public static void main(String[] args) {
int[] num = new int[6]; int[] com = new int[7]; random_num(num); random_com(com); check(com, num); for(int i = 0; i <num.length;i++){ System.out.print(num[i] + " "); } System.out.println(); for(int i = 0; i <com.length;i++){ System.out.print(com[i] + " "); } } private static void check(int[] com, int[] num) { // 점수 계산 int count = 0; for (int i = 0; i < com.length - 1; i++) { for (int j = 0; j < com.length - 1; j++) { if (com[i] == num[j]) { count++; } } } if (count == 6) { System.out.println("100점"); } else if (count == 5) { for (int i = 0; i < com.length - 1; i++) { if (com[6] == num[i]) { System.out.println("80점"); return; } } System.out.println("60점"); } else if (count == 4) { System.out.println("40점"); } else if (count == 3) { System.out.println("20점"); }else{ System.out.println("틀렸습니다"); } } private static void random_num(int[] num) { // 무작위 번호 생성 for (int i = 0; i < num.length; i++) { num[i] = (int) (Math.random() *45) + 1; if (i > 0) { for (int j = 0; j <= i - 1; j++) { if (num[j] == num[i]) { i--; continue; } } } } } private static void random_com(int[] com) { // 무작위 번호 생성 for (int i = 0; i < com.length; i++) { com[i] = (int) (Math.random() *45) + 1; if (i > 0) { for (int j = 0; j <= i - 1; j++) { if (com[j] == com[i]) { i--; continue; } } } } } }
음.. 문제를 잘못 이해하신 것 같습니다.
번호 6개를 출력해서 서버 내부의 답과 일치하면 로또 당첨(즉 100점) 이런 식입니다.
댓글을 작성하려면 로그인해야 합니다.
ki321123 7년 전
자바로 작성하였습니다. 계속 틀렸다고 나와서 그러는데 어디가 문제인가요
public class Main {
public static void main(String[] args) {
int[] num = new int[6];
int[] com = new int[7];
random_num(num);
random_com(com);
check(com, num);
for(int i = 0; i <num.length;i++){
System.out.print(num[i] + " ");
}
System.out.println();
for(int i = 0; i <com.length;i++){
System.out.print(com[i] + " ");
}
}
private static void check(int[] com, int[] num) { // 점수 계산
int count = 0;
for (int i = 0; i < com.length - 1; i++) {
for (int j = 0; j < com.length - 1; j++) {
if (com[i] == num[j]) {
count++;
}
}
}
if (count == 6) {
System.out.println("100점");
} else if (count == 5) {
for (int i = 0; i < com.length - 1; i++) {
if (com[6] == num[i]) {
System.out.println("80점");
return;
}
}
System.out.println("60점");
} else if (count == 4) {
System.out.println("40점");
} else if (count == 3) {
System.out.println("20점");
}else{
System.out.println("틀렸습니다");
}
}
private static void random_num(int[] num) { // 무작위 번호 생성
for (int i = 0; i < num.length; i++) {
num[i] = (int) (Math.random() *45) + 1;
if (i > 0) {
for (int j = 0; j <= i - 1; j++) {
if (num[j] == num[i]) {
i--;
continue;
}
}
}
}
}
private static void random_com(int[] com) { // 무작위 번호 생성
for (int i = 0; i < com.length; i++) {
com[i] = (int) (Math.random() *45) + 1;
if (i > 0) {
for (int j = 0; j <= i - 1; j++) {
if (com[j] == com[i]) {
i--;
continue;
}
}
}
}
}
}