【发布时间】:2015-09-12 11:14:09
【问题描述】:
我试图理解给出的答案,但我不明白为什么答案是“Hello World”,希望有人解释。
public class TestClass{
public static int getSwitch(String str){
return (int) Math.round( Double.parseDouble(str.substring(1, str.length()-1)) );
}
public static void main(String args []){
switch(getSwitch(args[0])){
case 0 : System.out.print("Hello ");
case 1 : System.out.print("World"); break;
default : System.out.print("Good Bye");
}
}
}
上面的代码用命令行运行会打印什么:java TestClass --0.50(0前有两个减号)
【问题讨论】:
-
getSwitch函数返回什么?另外,您忘记在case 0:子句之后加上break;。 -
@TheCodingMonk OP 没有编写代码,
break被故意省略,作为一个练习来展示缺少的中断意味着什么。
标签: java