pk16300 2017-11-01 08:37 采纳率: 0%
浏览 1727

switch 中嵌套for循环

如下代码为何还会执行for循环,明明for循环在case 30里面呀?
public class Test {
public static void main(String args[]){
int x = 40;

  switch( x ){

     case 10:
     System.out.print("Value of X is 10");
     break;

     case 20:

     System.out.print("Value of X is 20");
     break;

     case 30:
     System.out.println("Value of X is 30");

     for(;x<=50;){
     x++;
     }
     //break;

     case 40:
     System.out.println("Value of X is 40");
     //break;

     case 50:
     System.out.println("Value of X is 50");
     //break;


     default:
     System.out.println("这是 default 语句");

    }

 System.out.print("x=" + x);

}
}

  • 写回答

3条回答 默认 最新

  • 成_蹉_跎 2017-11-01 09:24
    关注

    我复制你的代码之后的运行结果,case 30: 并没有执行

     Value of X is 40
    Value of X is 50
    这是 default 语句
    x=40请按任意键继续. . .
    
    评论

报告相同问题?

悬赏问题

  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿