ArrayList的泛型

来源:互联网 发布:淘宝清除缓存在哪里 编辑:程序博客网 时间:2024/05/18 14:44

题目:两个乒乓球队进行比赛,各出三人。甲队为a,b,c三人,乙队为x,y,z三人。已抽签决定比赛名单。有人向队员打听比赛的名单。a说他不和x比,c说他不和x,z比,请编程序找出三队赛手的名单。  

程序分析:判断素数的方法:用一个数分别去除2到sqrt(这个数),如果能被整除,   则表明此数不是素数,反之是素数。  


import java.util.ArrayList;

public class test {
     String a,b,c;
     public static void main(String[] args) {
      String[] op = { "x", "y", "z" };
      ArrayList<test> arrayList=new ArrayList<test>();
      for (int i = 0; i < 3; i++)
       for (int j = 0; j < 3; j++)
        for (int k = 0; k < 3; k++) {
        test a=new test(op[i],op[j],op[k]);
         if(!a.a.equals(a.b)&&!a.b.equals(a.c)&&!a.a.equals(a.c)&&!a.a.equals("x")
           &&!a.c.equals("x")&&!a.c.equals("z")){
          arrayList.add(a);
         }
        }
      for(Object a:arrayList){
      System.out.println(a);
      }
     }
     public test(String a, String b, String c) {
      super();
      this.a = a;
      this.b = b;
      this.c = c;
     }
     @Override
     public String toString() {
      // TODO Auto-generated method stub
      return "a的对手是"+a+","+"b的对手是"+b+","+"c的对手是"+c+"\n";
     }
}
0 0
原创粉丝点击