练习03 Java 流程控制练习题目.docxVIP

  • 3
  • 0
  • 约3.35千字
  • 约 7页
  • 2022-10-31 发布于上海
  • 举报
编辑版 编辑版 word 第 3 讲 Java 流程控制 [] 选择题 给出代码: 1 class First 2 { 3 public static void main(String[] args) 4 { 5 double x=1; 6 if(x0.34) then { 7 x=x-0.1; 8 } 9 } 10 } 编译此类的结果是什么? A: 编 译 无 错 误 。 B:编译错误,由于第 5 行错误。 C:编译错误,由于第 6 行错误。 D:编译错误,由于第 7 行错误。答: 给出类定义如下: public class Second { public void loop() { byte i=-1; long j=2; 5 if (i= =1) (j= = 2) { 6 j=j-j+j; 7 } 8 } 9 } 编译此类结果是什么? A:编译成功,没有错误。 B:编译错误因为第 2 行有错误。 C:编译错误因为第 3 行有错误。 D:编译错误因为第 5 行有错误。 E:编译错误因为第 6 行有错误。答: 下列哪个类型可以在switch 的表达式中使用? A:int B:long C:byte D:String 答: 使用在 switch 语句中当没有匹配的情况下的语句是: A:if B:then C:others D:default E: else 答: 基本 for 循环需要哪些组成部分? A:初始部分语句。 B: 条 件 表 达 式 。 C: 增 量 部 分 语 句 。 D:以上都不需要。 答: 给出如下代码: public class The { public static void main(String[] args) { 13 for(int i=0;i10;) { 5 if(i=0) 6 System.out.print(“i=1”); 7 ++i; 8 } 9 } 10 } 在以上代码中或许有错误,下列哪个说法是真实的: A:如果i 在 for 中定义,则i 在 for 循环中必须进行增量处理。B:在 Java 中,if 语句一定要有{}。 C:此类或许有其他错误。D:此类没有错误。 答: 下列的循环结构中,那种保证一定能进入循环: A:while B: do- while C: for D: 以上都不能保证。答: 给出类代码: public class A int{ int public { c(long x) int y=0; switch(x) { case 1: y=x; break; case 2: y=x+1; break; } } return y; } } 此类能否正确编译?如果不能,有哪些语句有错误?错误的原因是什么? 答: 我们要创建一种可以至少运行一次的循环,应该使用什么循环语句A:while B:do while C:for D:以上都不是。答: 给出类代码: public class A { public static void main(String[] args) { for(int i=0;i2;i++) { switch(i) { case 0: System.out.print(i); case 1: System.out.print(i); break; } } System.out.println(End); } } 运行的结果是: A:01End B:0End C:1End D:001End E:End 答: 给出代码: public class A { public static void main(String[] args) { System.out.println(i=+i); } } 在虚线处放置那个循环语句,可以产生结果: i=0 i=1 选择: A:for(int i=-1;i2;++i) B:for(int i=1;i3;++i) C:for (int i=0; i2 ; i++) D:for (int i=0; i2; i++) 答: 给出代码: public class A { public static void main(String[] args) { int i=1; do while(i1) System.out.println(i=+i); while(i1); } } 执行此类的运行结果为: A: 代码无法编译 B: i=1 打 印 1 次C: 无任何输出D: i=1 打 印 2 次E: i=1 打印无数次答: 给出类代码: pub

文档评论(0)

1亿VIP精品文档

相关文档