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