JAVA经典算法(十八)

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

package cn.ls.lanqiao;

public class Test18 {

	public static void main(String[] args) {
		char a = 0;
		char b = 0;
		char c = 0;
		char str;
		for (str = 'x'; str <= 'z'; str++) {
			if (str != 'x' && str != 'z') {
				c = str;
			}
		}
		for (str = 'x'; str <= 'z'; str++) {
			if (str != 'x' && str != 'y') {
				a = str;
			}
		}
		for (str = 'x'; str <= 'z'; str++) {
			if (str != 'y' && str != 'z') {
				b = str;
			}
		}
		System.out.println("a的对手是" + a);
		System.out.println("b的对手是" + b);
		System.out.println("c的对手是" + c);
	}
}

 

posted @ 2020-01-18 11:09  小帅学java  阅读(8)  评论(0)    收藏  举报