zyanki/hitandblow — pull request #2 by zyanki (2014-12-03 05:49:01+00:00)
Title: Revert "Update README.md"

import java.util.Random;
import java.io.*;

final class Question{
private final int[] question = {0,1,2,3,4,5,6,7,8,9};
private final int tmp;
private final int i;

private Question(){
for (this.i = 0; this.i < question.length;i++) {
int rand = new Random().nextInt(10);
tmp = question[rand];
question[rand] = question[9];
question[9] = tmp;
}
System.out.println(question[0]+""+question[1]+""+question[2]+""+question[3]);
}
public int[] getQestion{
return question[];
}
}

final class Input{
private final int input;
private final int num;
private final int flag = 0 ;
private Input(){
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
try {
String buf = br.readLine();
input = Integer.parseInt(buf);
String str = String.valueOf(buf);
num = str.length();
} catch (Exception e) {
System.out.println("入力は数値のみです。");
flag = 1;
}
}
}

final class Inputsetter{
private final int [] ans3 = new int[4];
private final int hoge =0;
private Inputsetter(Input input){
ans3[3]=input.input%10;
ans3[2]=input.input/10%10;
ans3[1]=input.input/10/10%10;
ans3[0]=input.input/10/10/10%10;

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

} else {
if (ans3[i] == ans3[j] ) {
System.out.println("入力に重複があります");
input.flag = 1;
break;
}
}
}
if (input.flag == 1) {
break;
}
}
}
public int[] ansGet(){
return ans3;
}
}

final class Ans_check{
private final int hit = 0;
private final int blow = 0;
private final int count2 = 0;
private Ans_check(int flag, int count, Inputsetter ans, Question q) {
count2 = count;
if (flag == 0) {
for(int i = 0;i < 4; i++) {
for(int j = 0;j < 4; j++) {
if(i == j) { //hit check
if(q.question[i] == ans.ans3[j]) {
hit++;
} else {

}
} else { //blow check
if (q.question[i] == ans.ans3[j]) {
blow++;
} else {

}
}
}
}

if (hit == 4) {
System.out.println("正解！");
//return;
} else {
System.out.println("hit="+hit+",blow="+blow);
}

count2 = count;
count2++;
}
}
}

public class hitandblow2 {
static public void main (String[] args) throws IOException {
Question q = new Question();
int count = 1;
while (true) {
System.out.println("4桁の数値を入力してください。(" + count +"回目)");
Input input = new Input();

if(input.flag == 0){
if (input.num != 4) {
System.out.println("入力が4桁ではありません");
continue;
}
Inputsetter ans = new Inputsetter(input);
Ans_check aaa = new Ans_check(input.flag,count,ans,q);
count = aaa.count2;
if(aaa.hit == 4){
return;
}
}
}
}
}