首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
执行如下程序: public class Test { public static void main (String args[]) { int x=1,a=0,b=0; switch (x
执行如下程序: public class Test { public static void main (String args[]) { int x=1,a=0,b=0; switch (x
admin
2010-12-17
31
问题
执行如下程序: public class Test { 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=2,b=2
答案
A
解析
本题关键是要搞清楚该程序执行了哪几条语句。由于x的值等于1,所以switch结构中,程序从case1后面的语句开始执行,又因为case1后面的语句没有以break结束,所以程序要继续往下执行case 2后面的语句。所以,该程序共执行了这3条语句:a++;a++;b++;因此,变量a和b最后的值应该为2和1。
转载请注明原文地址:https://jikaoti.com/ti/mPH0FFFM
本试题收录于:
二级Java题库NCRE全国计算机二级分类
0
二级Java
NCRE全国计算机二级
相关试题推荐
构成计算机软件的是
下列选项中属于面向对象设计方法主要特征的是
算法的时间复杂度是指
数据库设计的四个阶段是:需求分析、概念设计、逻辑设计和
十进制整数设为整数类I,则下面属于类I的实例的是
0x4DC0是一个十六进制数,它对应的Unicode编码是中国古老的《易经》六十四卦的第一卦,请输出第51卦(震卦)对应的Unicode编码的二进制、十进制、八进制和十六进制格式。print(’’二进制{①}、十进制{②}、八进制{③}、\十六进制{④}
关于Python语句P=-P,以下选项中描述正确的是
以下选项中,对文件的描述错误的是
以下Python语言关键字在异常处理结构中用来捕获特定类型异常的选项是
所有由Container派生的类称为______。
随机试题
女性,30岁,婚后5年,因事业发展考虑,半年后计划妊娠。曾手术流产1次,药物流产2次,近次流产1月前。前来咨询避孕的方法。该女性在放置IUD后2年,停经53天再次妊娠,B超显示宫腔内妊娠囊2.9cm,未见IUD影像,盆腔X线片显示IUD位于左骶髂关节前
以医院为基础的病例对照研究,最常见的偏倚是
插置双气囊三腔管适用于哪种疾病出血
特种设备发生的重大安全事故,应向()报告。
热力管网中需要添加补偿器的原因不包括()。
一般而言,企业存货需要量与企业生产及销售的规模成正比,与存货周转一次所需天数成反比。( )
导游员在导游活动中应遵循因人而异、因地制宜、因时而变这三大导游讲解的基本原则。()
“节食族”是指那些早餐吃水果、午餐吃蔬菜,几乎不吃高热量食物的人。在这个物品丰盛的时代,过度节食,就像把一个5岁的孩子带进糖果店,却告诉他只能吃一个果冻。营养专家指出,这种做法既不科学也不合乎情理。如果以下哪项陈述为真,能给专家的观点以最有力的支
1960年~1970年间,非洲国家津巴布韦境内的狩猎者猎捕了6500多头大象以获取象牙,这一时期津巴布韦大象总数从35000头下降到30000头以下。1970年津巴布韦采取了保护大象的措施,1970年~1980年间逮捕并驱逐了800多名狩猎人。但是,到19
设n元线性方程组Ax=0和Bx=0_则,r(A)=r(B)是两线性方程组同解的().
最新回复
(
0
)