菜鸟涂鸦作品展_No.18

//【程序18】 题目:两个乒乓球队进行比赛,各出三人。甲队为a,b,c三人,乙队为x,y,z三人。
//已抽签决定比赛名单。有人向队员打听比赛的名单。a说他不和x比,c说他不和x,z比,
//请编程序找出三队赛手的名单。
public class _18_pingpang {
int shuchu(int num){
if (num==1)
System.out.println("和选手x进行比赛");
if (num==2)
System.out.println("和选手y进行比赛");
if (num==3)
System.out.println("和选手z进行比赛");
return 0;
}
public static void main(String[] args){
_18_pingpang pp=new _18_pingpang();
int a=0;
int b=0;
int c=0;
int flag=0;
for (int i=1 ; i<=3 ; i++){
flag=0;
a=i;
for (int j=1 ; j<=3 ; j++){
if(flag==1)
break;
b=j;
if (b==a)
continue;
for (int k=1 ; k<=3 ; k++){
c=k;
if (c==a || c==b)
continue;
if (a==1){
flag=1;break;
}
if (c==1 || c==3){
flag=1;break;}
if (a==b || b==c || a==c){
flag=1;break;}
System.out.print("选手a");pp.shuchu(a);
System.out.print("选手b");pp.shuchu(b);
System.out.print("选手c");pp.shuchu(c);
}
}
}
}
}

涂鸦心得:

  这个程序还用debug调了一会儿,原因是在找到合适的安排之后,应该立即停止输出结果,这个debug的过程还算有点意义。。。

原文地址:https://www.cnblogs.com/aniuer/p/2663441.html