1 public class Xixueguinumber
2 {
3
4 public int cal(int x, int y, int z, int w)
5 {
6 int num = (x * 10 + y) * (z * 10 + w);
7 return num;
8
9 }
10 public static void main(String[] args)
11 {
12 for (int i = 1000; i <= 9999;i++)
13 {
14 int a = (int)(i/1000);
15 int b = (int)((i - a*1000)/100);
16 int c = (int)((i-((int)(i/100))*100)/10);
17 int d = (int)(i - ((int)(i/10))*10);
18 Xixueguinumber Xi = new Xixueguinumber();
19 boolean b1 = Xi.cal(a,b,c,d) == i;
20 boolean b2 = Xi.cal(b,a,c,d) == i;
21 boolean b3 = Xi.cal(a,b,d,c) == i;
22 boolean b4 = Xi.cal(b,a,d,c) == i;
23 boolean b5 = Xi.cal(a,c,b,d) == i;
24 boolean b6 = Xi.cal(a,c,d,b) == i ;
25 boolean b7 = Xi.cal(c,a,b,d) == i;
26 boolean b8 = Xi.cal(c,a,d,b) == i;
27 boolean b9 = Xi.cal(a,d,b,c) == i;
28 boolean b10 = Xi.cal(d,a,b,c) == i;
29 boolean b11 = Xi.cal(a,d,c,b) == i;
30 boolean b12 = Xi.cal(d,a,c,b) == i;
31 Boolean array[] ={b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12};
32 for(int j = 0; j <12; j++)
33 {
34 if(array[j])
35 {
36 System.out.print("吸血鬼数字为:" + i + "=" );
37 switch(j+1)
38 {
39 case 1 : System.out.println(""+ a + b + " * " + c + d);break;
40 case 2 : System.out.println(""+ b + a + " * " + c + d);break;
41 case 3 : System.out.println(""+ a + b + " * " + d + c);break;
42 case 4 : System.out.println(""+ b + a + " * " + d + c);break;
43 case 5 : System.out.println(""+ a + c + " * " + b + d);break;
44 case 6 : System.out.println(""+ a + c + " * " + d + b);break;
45 case 7 : System.out.println(""+ c + a + " * " + b + d);break;
46 case 8 : System.out.println(""+ c + a + " * " + d + b);break;
47 case 9 : System.out.println(""+ a + d + " * " + b + c);break;
48 case 10 : System.out.println(""+ d + a + " * " + b + c);break;
49 case 11 : System.out.println(""+ a + d + " * " + c + b);break;
50 case 12 : System.out.println(""+ d + a + " * " + c + b);break;
51 }
52 }
53
54 }
55
56 }
57 }
58 }
感觉蛮好玩的.
芳儿宝贝.我爱你