1  public class demo {
 2      public static void main(String[] args) {
 3       int a,b,c,d;//代表四个学生
 4           boolean x1,x2,x3;//代表三位老师
 5            for(a=1;a<=4;a++){
 6                for(b=1;b<=4;b++) {//a,b,c,d的值不能相同,并且a+b+c+d的值为1+2+3+4=10;
 7  
 8                    if(a==b) continue;
 9                    for(c=1;c<=4;c++) {
10                      if(a==c) continue;
11                       if(b==c) continue;
12                      d=10-a-b-c;
13                       x1=(a==1)^(b==3);//代表三位老师说的话有一句是正确的,用亦或来表示
14                       x2=(c==1)^(d==4);
15                       x3=(d==2)^(a==3);
16                       if(x1==true&&x2==true&&x3==true)
17                          System.out.println(a+" "+b+" "+c+" "+d);
18                       }
19                   }
20           }                                         
21      }
22  }