use*_*379 1 java switch-statement
我正在网上学习Java并且在切换课程中上课.为了愚弄,我会在特定情况(将被执行)之后删除其中一个中断.我曾想过它会检查下一个案例,看看条件是否为false,并在退出前跳到默认情况.相反,它执行了不正确的情况并在默认情况之前中断.
这里出了什么问题?
public class Switch {
public static void main(String[] args) {
char penaltyKick = 'R';
switch (penaltyKick) {
case 'L': System.out.println("Messi shoots to the left and scores!");
break;
case 'R': System.out.println("Messi shoots to the right and misses the goal!");
case 'C': System.out.println("Messi shoots down the center, but the keeper blocks it!");
break;
default:
System.out.println("Messi is in position...");
}
}
}
Run Code Online (Sandbox Code Playgroud)
编辑:忘了提.输出是:
Messi shoots to the right and misses the goal!
Messi shoots down the center, but the keeper blocks it!
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
665 次 |
| 最近记录: |