




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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届数学三下期末联考试题含解析
- 浙江音乐学院《锅炉原理B》2023-2024学年第一学期期末试卷
- 四川文化传媒职业学院《汽车理论A》2023-2024学年第二学期期末试卷
- 重庆轻工职业学院《工程光学设计(双语)》2023-2024学年第二学期期末试卷
- 七台河市重点中学2025年学业水平考试英语试题模拟题卷含解析
- 上海立信会计金融学院《医学免疫学与微生物学》2023-2024学年第二学期期末试卷
- 内蒙古自治区海勃湾区2025年初三下第三次月考化学试题含解析
- 湖南医药学院《中医诊断学技能》2023-2024学年第一学期期末试卷
- 2025年天津市南开区中考一模语文试题(含答案)
- 2025年磁粉探伤工职业技能鉴定理论考试题库(浓缩500题)
- 婚姻保证忠诚协议书
- 新2024年-北京市房屋租赁合同自行成交版
- 有效工作时间管理
- 2025年安徽省铜陵市枞阳县浮山中学高三下学期3月适应性考试历史试题含解析
- 劳动合同法员工培训课件
- 2025年上海市房屋租赁合同模板(标准版)
- 智慧城市中的公民参与-全面剖析
- 麻醉科急救处理职责
- 安全文明施工保证措施及承诺
评论
0/150
提交评论