




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、Java 2实用教程第5版_第3章 switch选择结构 课堂练习复制Java 2实用教程第4版_第3章 switch选择结构 课堂练习,只能作答一次,计入期末成绩基本信息:矩阵文本题 *姓名:_学号:_1.在Java中,下列代码段的输出为()int score=60;switch(score)case 60:System.out.print(“中等”);case 80:System.out.print(“良好”);break;case 80:System.out.print(“优秀”); 单选题 *中等中等良好(正确答案)中等优秀中等良好优秀2.在Java语言中有如下代码,下列x的定义中,可
2、以使用该段代码输出100的是()switch(x)case 100:System.out.println(“100”);break;case 110:System.out.println(“110”);break; 单选题 *int x=100;(正确答案)double x=100;String x=”100”;float x=110;3.在Java中,关于switch的说法正确的是()。 单选题 *switch():括号里必须放一个整型常量或字符型常量case后可以是一个整型或是字符型的常量(正确答案)default表示不考虑其它case语句,优先执行break表示跳出当前case块,继续执
3、行其它case块4、在Java中,以下代码段的运行结果是()。public static void main(String args)float f=1;switch(f)case 1:System.out.print(“1”);case 2:System.out.print(“,2”);default:System.out.print(“,default”); 单选题 *11,21,2,default编译错误(正确答案)6.在Java中,switch语句中控制表达式的类型可以是()(选择多项) *byte(正确答案)short(正确答案)char(正确答案)float7.在Java的swit
4、ch语句中,有如下代码段:switch(x)case1:System.out.println(“1”);break;case 2:System.out.println(“2”);break;defalut:System.out.println(“非数字”);对于变量x取()进行定义它的类型时,程序输出结果为2。() 单选题 *char x=2;float x=2;int x=2;(正确答案)以上都不正确8.在Java中,设a=2、b=4为int型变量,x=3f、y=5f为float型变量且它们均已被赋值,则下列语句中正确的是()。( 单选题 *switch(x+y)switch(ch+1)sw
5、itch chswitch(a+b)(正确答案)9.在Java中,下列有关switch的说法,正确的是() 单选题 *switch结构可以完全替代多重if结构条件判断为等值判断,并且判断的条件为数组时,可以使用switch结构条件判断为等值判断,并且判断的条件为字符时,可以使用switch结构(正确答案)条件判断为等值判断,并且判断的条件为double时,可以使用switch结构11.阅读下面Java代码片段,正确的输出结果是()。int num = 5;switch (num / 25) case 1:System.out.print(铅笔);break;case 2:System.out.
6、print(钢笔);break;default:System.out.print(坏笔);case 3:System.out.print(圆珠笔);break;case 4:System.out.print(毛笔);break; 单选题 *毛笔坏笔坏笔圆珠笔(正确答案)编译错误答案解析:11.阅读下面Java代码片段,正确的输出结果是()。int num = 5;switch (num / 25) case 1:System.out.print(铅笔);break;case 2:System.out.print(钢笔);break;default:System.out.print(坏笔);br
7、eak;case 3:System.out.print(圆珠笔); case 4:System.out.print(毛笔);break; 单选题 *毛笔坏笔(正确答案)坏笔圆珠笔编译错误答案解析:12.以下是文件HelloAccp.java文件中的代码,请分析该段代码的运行结果是()public class HelloAccppublic static void main(String args)char str = 2;switch (str) case 1:System.out.println(Im First!);case 2:System.out.println(Im Second!)
8、;break;单选题 *Im First!第3行存在错误:缺少break语句Im First!Im Second!Im Second!(正确答案)13.阅读以下Java代码,在横线处填入(),输出结果中可以包含“3”。public class Demopublic static void main(String args)int a=_;switch(a)default:System.out.println(default);break;case 1:System.out.println(1);break;case 2:System.out.println(2);case 3:System.o
9、ut.println(3); (选择两项) *43(正确答案)2(正确答案)default14.在Java语言和C#语言中均可以使用switch结构解决等值判断问题,以下Java代码的运行结果是()。public class HelloAccppublic static void main(String args)int sw=0;switch(sw)case 0:System.out.print(“你成功了!”);case 2:System.out.print(“你失败了!”);break; 单选题 *你成功了!你失败了!(正确答案)你失败了!你成功了!出现编译错误,因为缺少default子
10、句答案解析:15.执行下列Java代码片段,输出结果正确的是()。int num=5;switch(num)default:System.out.println(“天蝎座”);break;case 1:Sysetm.out.println(“巨蟹座”);break;case 2:Sysetm.out.println(“射手座”);case 3:case 4:Sysetm.out.println(“双子座”); 单选题 *天蝎座(正确答案)天蝎座巨蟹座编译错误编译正确,什么也不输出16.分析下面的Java代码,程序的输出结果是()。Public class TestPublic static v
11、oid main(String args)int num=1;switch(num)case 0:case 1:num+;case 2:num-;num-;System.out.println(num); 单选题 *0(正确答案)12代码有错,程序出现死循环17.在Java中,以下代码的运行结果是()。public class Testpublic static void main(String args)char a=y;switch(a)case y:System.out.println(“hello”);break;case n:System.out.println(“你好”);brea
12、k;default:System.out.println(“other”);break; 单选题 *hello(正确答案)other编译错误运行错误18.在jdk1.5环境运行以下文件HelloAccp.java文件中的代码,请分析该段代码的运行结果是()public class HelloAccppublic static void main(String args)String str=1;switch(str)case 1:System.out.println(“Im First!”);case 2:System.out.println(“Im Second!”);break; 单选题 *Im First!第3行存在错误:缺少bre
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 交通事故责任财产保全执行合同
- 财产赠与与投资合作合同范本
- 采矿权抵押贷款合同示范文本
- 融资租赁式餐饮店铺转让及运营管理合同
- 儿童身高管理活动方案
- 老人护理课件
- 老人健康养生课件
- 美术说课课件下载
- 美术画图案课件
- 防火灾事故应急预案
- 2025年地区事业单位招聘公共基础知识重点难点突破试题
- 2025变压器类产品型号注册管理
- 推进教师跨学科教学能力提升方案
- 职业院校与企业深度合作2025年校企合作人才培养质量提升策略与实践报告
- 2025党考试题及答案
- 水路运输安全管理培训
- 中国支付体系行业市场运行现状及投资规划建议报告
- 医院后勤礼仪培训课件
- 《咕咚》课件 小学语文一年级下册
- 小学二年级下册竖式计算题400道
- LS-T8014-2023高标准粮仓建设标准
评论
0/150
提交评论