import java.util.Random;
import java.util.Scanner;
public class Demo_01 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Random r = new Random();
Scanner sc = new Scanner(System.in);
int temp = r.nextInt(900) + 100;
int a = temp / 10 / 10 % 10;// 百位
int b = temp / 10 % 10;// 十位
int c = temp % 10;
boolean flag = true;
int index;
System.out.println(temp);
while (flag) {
System.out.println("请猜数字(100~1000):");
index = sc.nextInt();
if (temp == index) {
System.out.println("猜对了--I 服了--YOU--");
flag = false;
} else {
int x = index / 10 / 10 % 10;// 百位
int y = index / 10 % 10;// 十位
int z = index % 10;
int id = 0;
int idd = 0;
if (y == b) {
id++;
}
if (x == a) {
id++;
}
if (z == c) {
id++;
}
if (a == x) {
idd++;
}
if (a == y) {
idd++;
}
if (a == z) {
idd++;
}
if (b == x) {
idd++;
}
if (b == y) {
idd++;
}
if (b == z) {
idd++;
}
if (c == x) {
idd++;
}
if (c == y) {
idd++;
}
if (c == z) {
idd++;
}
System.out.println("猜对" + id + "个位置\n猜对:" + idd + "个数");
}
}
}
}
|
|