반응형
package bullscows;
import java.util.Scanner;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int cows = 0;
int bulls = 0;
boolean flag = true;
String userInput = sc.nextLine();
char[] chars = userInput.toCharArray();
int[] answers = {9,3,0,5};
int[] nums = new int[chars.length];
int option = 0;
for (int i =0; i < chars.length;i++){
nums[i] = Character.getNumericValue(chars[i]);
if (nums[i] == 9 || nums[i] == 3 || nums[i] == 0 || nums[i] == 5) {
if (nums[i] == answers[i]) {
bulls++;
} else {
cows++;
}
}
}
if(bulls == 0 && cows == 0){
System.out.println("Grade: None. The secret code is 9305.");
}else {
if (bulls == 0) {
System.out.println("Grade: " + cows + " cow(s). The secret code is 9305.");
} else if (cows == 0) {
System.out.println("Grade: " + bulls + " bull(s). The secret code is 9305.");
} else {
System.out.println("Grade: " + bulls + " bull(s) and " + cows + " cow(s). The secret code is 9305.");
}
}
}
}
반응형
'Java > JetBrain Project' 카테고리의 다른 글
JetBrain [Easy] Bulls and Cows - Stage 3 (0) | 2020.12.29 |
---|---|
JetBrain [Easy] Bulls and Cows - Stage 1 (0) | 2020.12.10 |
JetBrain [Easy] Tic Tac Toe - Stage 5 (0) | 2020.12.10 |
JetBrain [Easy] Tic Tac Toe - Stage 4 (0) | 2020.12.10 |
JetBrain [Easy] Tic Tac Toe - Stage 3 (0) | 2020.12.09 |