qq_43807726
qq_43807726
2019-01-09 13:03

请问怎么跳出while循环

  • java

输入“End”后还是要我继续输入,没有结束循环
import java.util.Scanner;

public class Main_剪刀石头布 {

public static void main(String[] args) {
    // TODO Auto-generated method stub
       Scanner in = new Scanner(System.in);
       String []p= {"JianDao","ChuiZi","Bu"};
       int n =in.nextInt(),cnt=0,i=0;
       String [] P=new String [100]; 
       String c;
       c=in.next();
       while(c!="End") {
             ++i;
           P[i]=c;
           ++cnt;
           c=in.next();
         }
    for (int j = 1; j <=cnt; j++) {
        if(j%(n+1)==0) System.out.println(P[j]);
        else {
        if(P[j]=="JianDao") System.out.println("ChuiZi");
        else if(P[j]=="ChuiZi") System.out.println("Bu");
        else System.out.println("JianDao");
    }
    }

}
}

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答