首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序 public class Sun { public static void main(String args[ ]) { int x=1,a=0,b=0; switch(x)
有如下程序 public class Sun { public static void main(String args[ ]) { int x=1,a=0,b=0; switch(x)
admin
2010-07-28
24
问题
有如下程序 public class Sun { public static void main(String args[ ]) { int x=1,a=0,b=0; switch(x) { case 0:b++; case 1:a++; case 2: a++; b++; } System.out.println("a="+a+","+"b="+B) } }该程序的输出结果是( )。
选项
A、a=2,b=1
B、a=1,b=1
C、a=1,b=0
D、a=0,b=0
答案
1
解析
该题考查对switch-case-break语句的理解。该题x=1与case 1语句匹配,执行a++语句,a的值为1,而case 1语句后没有break语句,所以程序继续向下执行case 2语句,a++, b++,a的值为2,b的值为1。故本题答案选项是A。
转载请注明原文地址:https://jikaoti.com/ti/rfH0FFFM
本试题收录于:
二级Java题库NCRE全国计算机二级分类
0
二级Java
NCRE全国计算机二级
相关试题推荐
下列选项中不属于软件生命周期开发阶段任务的是
以下主机地址所代表的主机在地理位置上属于中国的是
下列说法错误的是
冯.诺依曼型体系结构中两个重要的概念是
下列选项中不属于面向对象程序设计特征的是
某二叉树共有12个结点,其中叶子结点只有1个。则该二叉树的深度为(根结点在第1层)
软件调试的目的是
下面对对象概念描述正确的是
在面向对象方法中,实现信息隐蔽是依靠
______方法是不能被当前类的子类重新定义的方法。
随机试题
孕34周,早产儿,生后8小时出现呼吸困难,进行性加重,呼气时呻吟,时有呼吸暂停,两肺呼吸音低,未闻湿啰音。最可能的诊断是
注册安全工程师执业中因其过失造成当事人损失的,由()承担赔偿责任。
有关要约和承诺的说法,错误的是( )。
设备基础验收,主要检查验收其()是否符合设计要求。
委托任务和组织活动是属于()。
甲为报复同事乙,将“毒鼠强”投放于乙平时使用的茶杯中,乙饮用后不久出现中毒反应。甲见状,不忍见乙痛苦地死亡,立即拨打120求救。乙经抢救无效死亡。甲的行为属于:
在睡眠时出现△波的睡眠阶段有()
李浩、王鸣和张翔是同班同学,住在同一宿舍。其中,一个是湖南人,一个是重庆人,一个是辽宁人。李浩和重庆人不同岁,张翔的年龄比辽宁人小,重庆人比王鸣年龄大。根据题干所述,以下哪项是关于他们三人的年龄次序(由大到小)的正确表述?
结合材料,回答问题:材料1今年1月,我国中东部地区相继出现4次大范围雾霾天气,影响30个省(区、市)。其中1月6日一16日,中东部大部地区出现了入冬以来持续时间最长、影响范围最广、强度最强的雾霾天气过程。雾霾天气给大气环境、群众健康、交
1 Manypeopleseemtothinkthatsciencefictionistypifiedbythecoversofsomeoftheoldpulpmagazines;theBug-eyedMons
最新回复
(
0
)