[填空题] 下列程序段的输出结果为。int a=2;switch (a) case 2:System. out. print( "Value is 2.");ca

[填空题] 下列程序段的输出结果为。int a=2;switch (a) case 2:System. out. print( "Value is 2.");ca,第1张

[填空题] 下列程序段的输出结果为 。int a=2;switch (a) case 2:System. out. print( "Value is 2."); ca

[填空题] 下列程序段的输出结果为 【8】

int a=2;

switch (a)

case 2:

System. out. print( "Value is 2.");

case 3 :

System. out. println( "Value is 3. ");

break;

default:

System. out. println ("end ");

break;

正确答案:

Value is 2. Value is 3.

参考解析:

switch语句的表达式a将依次与case后的值进行匹配,如果遇到匹配的值,则执行该case子句后的语句序列。当表达式的值与任意一个case子句的值都不匹配时,执行default后的语句。break语句用来在执行完一个case子句后,使程序跳出switch语句。此题先执行case2后的语句再执行case 3后的语句,遇到case 3中的break语句后退出。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5584833.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-14
下一篇 2022-12-14

发表评论

登录后才能评论

评论列表(0条)

保存