首页 > 试题广场 >

两个乒乓球队进行比赛,各出三人。甲队为a,b,c三人,乙队为

[问答题]

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

public class Test18 {
    public static void main(String[] args) {
        char a,b,c;
        for(a = 'x'; a <= 'z'; a++) {
            for(b = 'x'; b <= 'z'; b++) {
                if(a != b) {   //避免参赛队员重复比赛
                    for(c = 'x'; c <= 'z'; c++) {
                        if(a != c && b != c) {      //避免参赛队员重复比赛
                            if(a != 'x' && c != 'x' && c != 'z') {   //根据题意判断
                                System.out.println("a和" + a + ",b和" + b + ",c和" + c + "进行比赛");
                            }
                        }
                    }
                }
            }
        }
    }
}

发表于 2019-06-08 16:45:40 回复(5)
import java.util.ArrayList;
import java.util.List;
public class Main {
	public static void main(String[] args) {
		 List<String> a = new ArrayList<String>();
		 List<String> b = new ArrayList<String>();
		 List<String> c = new ArrayList<String>();
		 a.add("y");
		 a.add("z");
		 b.add("x");
		 b.add("y");
		 b.add("z");
		 c.add("y");
		 
		 a.removeAll(c);
		 b.removeAll(c);
		 b.removeAll(a);
		 
		 System.out.println("a的对手:");
		 System.out.println(a.get(0));
		 System.out.println("b的对手:");
		 System.out.println(b.get(0));
		 System.out.println("c的对手:");
		 System.out.println(c.get(0));
	}
}

发表于 2019-10-17 21:57:21 回复(0)
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        char a = 0, b = 0, c = 0, str;
        for (str = 'x'; str <= 'z'; str++) {//x到z
            if (str != 'x' && str != 'z') {//c不和x,z比
                c = str;
            }
        }
        for (str = 'x'; str <= 'z'; str++) {
            if (str != 'x' && str != c) {//a不和x比,且不与c对手一样
                a = str;
            }
        }
        for (str = 'x'; str <= 'z'; str++) {
            if (str != a && str != c) {//b不与a,c对手一样
                b = str;
            }
        }
        System.out.println("a的对手"+a);
        System.out.println("b的对手"+b);
        System.out.println("c的对手"+c);
发表于 2019-08-28 17:02:54 回复(0)
class Main(){
    public static void main(String[] args){
        sout();
    }

    static void sout(){
        char[] a = new char[3];
        char[] b = new char[3];
        char[] c = new char[3];       }
}

发表于 2019-07-10 17:42:25 回复(0)
String temp1[] = {"a","b","c"};
String temp2[] = {"X","Y","Z"}; int k=-1; for (int i = 0; i < temp1.length; i++) {  for (int j = 0; j < temp2.length; j++) {  if(i==0&&j==0)  continue;  else if(i==2&&(j==0||j==2))  continue;  else {  if (i!=k) {
                System.out.println(temp1[i] + temp2[j]);
                k = i;
            }
        }
    }
}

发表于 2019-06-18 20:26:28 回复(0)