Two table tennis team list questions of judges prime Numbers
- 2020-06-15 08:33:11
- OfStack
Two table tennis teams play a match with three players each. Team A consists of a,b and c3, and team B consists of x,y and z3. The list of matches has been drawn up. Someone asked the players for the names of the matches. a says he is not competing with x, c says he is not competing with x,z, please program to find the names of the 3 teams.
Program analysis: The method of judging prime Numbers: divide 2 to sqrt(this number) with 1 number, if it can be divisible, it means that this number is not a prime number, and vice versa.
Program design:
import java.util.ArrayList;
public class pingpang {
String a,b,c;
public static void main(String[] args) {
String[] op = { "x", "y", "z" };
ArrayList<pingpang> arrayList=new ArrayList<pingpang>();
for (int i = 0; i < 3; i++)
for (int j = 0; j < 3; j++)
for (int k = 0; k < 3; k++) {
pingpang a=new pingpang(op[i],op[j],op[k]);
if(!a.a.equals(a.b)&&!a.b.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 pingpang(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 The opponent is "+a+","+"b The opponent is "+b+","+"c The opponent is "+c+"\n";
}
}