收藏 分销(赏)

《使用Java理解程序逻辑》内部测试笔试考试.doc

上传人:w****g 文档编号:2492915 上传时间:2024-05-30 格式:DOC 页数:13 大小:126KB
下载 相关 举报
《使用Java理解程序逻辑》内部测试笔试考试.doc_第1页
第1页 / 共13页
《使用Java理解程序逻辑》内部测试笔试考试.doc_第2页
第2页 / 共13页
点击查看更多>>
资源描述
《使用Java理解程序逻辑》内部测试笔试考试 13 / 13 ———————————————————————————————— 作者: ———————————————————————————————— 日期: 个人收集整理,勿做商业用途 《使用Java理解程序逻辑》内部测试-笔试试卷 1) 给定某Java程序的main方法如下所示,该程序的运行结果是( )。 public static void main(String[] args) { boolean boo = true; if (boo == false) { System.out.println("a"); } else { System.out.println("b"); } } A. 输出a B. 输出b C. 输出ab D. 运行时出错 2) 在Java中,下列代码的运行结果是( )。 public static void main(String[] args) { int a=1,b=2,c=3; if(a<0) if(b<0) c=10; else c=20; System.out.println(c); } A. 输出:10 B. 输出:20 C. 输出:3 D. 编译报错 3) 分析下面的Java程序段,编译运行后的输出结果是( )。 public class Test { public void changeString(StringBuffer sb) { sb.append("stringbuffer2"); } public static void main(String[] args) { Test a = new Test(); StringBuffer sb = new StringBuffer("stringbuffer1"); a.changeString(sb); System.out.println("sb = " + sb); } } A. sb = stringbuffer2stringbuffer1 B. sb = stringbuffer1 C. sb = stringbuffer2 D. sb = stringbuffer1stringbuffer2 4) 在Java中,包有多种用途,但不包含( )。 A. 将类组合成较小的单元,便于使用 B. 有助于避免命名冲突 C. 有助于提高运行效率 D. 允许在更广的范围内保护类、数据和方法 5) 在Java中,包com中定义了类TestUtil,在com的子包util中定义了同名类TestUtil,给定如下Java代码,编译运行时,将发生( )。 package net; import com.util.TestUtil; import com.TestUtil; public class Test { public static void main(String[] args) { TestUtil testutil = new TestUtil(); } } A. 创建了一个com.TestUtil对象 B. 创建了一个com.util.TestUtil对象 C. 创建了一个com.TestUtil对象和一个com.util.TestUtil对象 D. 编译无法通过 6) 编译并运行下面的Java代码,( )可能会出现在输出结果中。(选择两项) public class Test{ public static void main(String args[]) { for(int i = 0; i < 3; i++) { for(int j = 3; j >= 0; j--) { if(i == j) continue; System.out.println("i="+ i + " j="+j); } } } } A. i=0 j=3 B. i=0 j=0 C. i=2 j=2 D. i=0 j=2 E. i=1 j=1 7) 在Java中,( )关键字用来退出循环,将控制权转给程序的其他部分。 A. return B. continue C. break D. exit 8) 在Java语言的控制结构中,break语句是经常用到的语句。下面一段代码中break语句起到( )的作用。 int pointer = 0; while (pointer <= 10) { switch (pointer % 3) { case 1: pointer += 1; break; case 2: pointer += 2; break; default: pointer += 3; break; } } A. 结束当次循环,使控制权直接转移到控制循环的条件表达式 B. 从嵌套循环内部跳出最里面的循环 C. 终止switch语句的语句序列,提高switch-case语句性能 D. 退出循环 9) 在Java中,以下( )不属于Java基本数据类型。 A. int B. boolean C. String D. double 10) 分析下面的Java代码片段,编译运行后的输出结果是( )。 for (int i = 0; i < 6; i++) { int k = ++i; while(k <5) { System.out.print(i); break; } } A. 024 B. 02 C. 123 D. 13 11) 给定如下Java程序的代码片段,编译运行后的输出结果是( )。 for (int i = 0; i < 6; i++) { System.out.print(i+","); while(++i <5) { continue; } System.out.print(i); } A. 0,4,5 B. 0,4 C. 0,5 D. 0,6 12) 给定如下Java代码,编译运行后,输出的结果将是( )。 public class Test { public static void main(String args[]) { String s1 = new String("Test"); String s2 = new String("Test"); if (s1 == s2) System.out.println("Same"); if (s1.equals(s2)) System.out.println("Equals"); } } A. Same B. Equals C. Same Equals D. 什么都不输出 13) 给定如下Java程序的方法结构,则方法体实现语句正确的是( )。 public String change(int i){ //方法体 } A. return 100; B. return 'a'; C. return i+""; D. return i; 14) 给定Java代码如下所示,则编译运行后,输出结果是( )。 public class test{ static int i; public int aMethod() { i++; return i; } public static void main(String args[]) { Test test = new Test(); test.aMethod(); System.out.println(test.aMethod()); } } A. 0 B. 1 C. 2 D. 3 15) 给定一个Java程序的代码如下所示,则编译运行后,输出结果是( )。 public class Test { int count = 9; public void count1() { int count = 10; System.out.println("count1=" + count); } public void count2() { System.out.println("count2=" + count); } public static void main(String args[]) { Test t = new Test(); t.count1(); t.count2(); } } A. count1=9 count2=9 B. count1=10 count2=9 C. count1=10 count2=10 D. count1=9 count2=10 16) 在Java中,如果要在字符串类型对象s="java"中,得到字母 'v' 出现的位置,可使用以下( )语句。 A. s.matches('v'); B. s.charAt('v'); C. s.indexOf('v'); D. s.substring('v'); 17) 给定某Java程序的main方法如下,该程序编译运行后的结果是( )。 public static void main(String[] args) { String str=null; str.concat("abc"); str.concat("def"); System.out.println(str); } A. 输出:null B. 输出:abcdef C. 编译错误 D. 运行时出现异常 18) 给定一个Java程序的代码如下所示,则编译运行后,输出结果是( )。 public class Test { int count = 9; public void count1() { count = 10; System.out.println("count1=" + count); } public void count2() { System.out.println("count2=" + count); } public static void main(String args[]) { Test t = new Test(); t.count1(); t.count2(); } } A. count1=9 count2=9 B. count1=10 count2=9 C. count1=10 count2=10 D. count1=9 count2=10 19) 给定一个Java程序的代码如下所示,则编译运行后,输出结果是( )。 public class Test { int count = 9; public void count() { System.out.println("count=" + count++); } public static void main(String args[]) { new Test().count(); new Test().count(); } } A. count=9 count=9 B. count=10 count=9 C. count=10 count=10 D. count=9 count=10 20) 有关Java中的类和对象,以下说法错误的是( )。 A. 同一个类的所有对象都拥有相同的特征和行为 B. 类和对象一样,只是说法不同 C. 对象是具有属性和行为的实体 D. 类规定了对象拥有的特征和行为 21) 在Java语言中有如下代码,下列x的定义中,可以使该段代码输出100的是( )。 switch( x ) { case 100 : System.out.println("100"); break ; case 110 : System.out.println("110"); break ; } A. int x = 100; B. double x = 100; C. String x = "100"; D. int x = 110; 22) 在Java语言中,有如下代码: switch(x) { case 100 : System.out.println("One hundred"); break; case 200 : System.out.println("Two hundred"); break; case 300 : System.out.println( "Three hundred"); break; } 下列x的定义中,( )可以使得上段代码编译通过。(选择两项) A. double x = 100; B. char x = 100; C. String x = "100"; D. int x = 100; 23) 给定如下Java代码片段,编译运行时的结果是( )。 int i = 2; switch (i) { default: System.out.println("default"); case 0: System.out.println("zero"); break; case 1: System.out.println("one"); case 2: System.out.println("two"); } A. 输出:default B. 输出:default zero C. 编译出错,default语句的位置不符合switch 结构的语法结构 D. 输出:two 24) 给定如下Java代码片段,编译运行的结果是( )。 int i = 0, j = -1; switch (i) { case 0, 1: j = 1; case 2: j = 2; } System.out.print("j=" + j); A. 程序编译出错 B. 输出:j=1 C. 输出:j=2 D. 输出:j=0 25) 分析下面的Java代码,当x=2时,运行结果是( )。 switch (x) { case 1: System.out.println(1); case 2: case 3: System.out.println(3); case 4: System.out.println(4); } A. 没有输出任何结果 B. 输出结果为3 C. 输出结果是3和4 D. 输出结果是1、3和4 26) 给定如下Java代码片段,编译运行后,输出结果是( )。 String s="ABCDE"; System.out.print(s.substring(3).concat("FGH")); A. CDEFGH B. DEFGH C. FGH D. ABCDE 27) 分析如下的Java代码,编译运行时将输出( )。 String s = new String("ACCPTest"); int i = 1; int j = 4; System.out.println(s.substring(i,j)); A. ACCP B. ACC C. CCP D. CCPT 28) 分析如下的Java代码,编译运行的输出结果是( )。 public class Test { public static void main(String[] args) { String s; System.out.println("s=" + s); } } A. 编译通过,并且输出:s= B. 编译通过,并且输出:s=null C. 编译通过,无任何输出 D. 编译报错,s未初始化 29) 分析如下Java程序段,程序编译运行结果是( )。 public class A{ public static void main(String[] args) { int num = 0; switch (num) { default: System.out.println("Default"); num++; case 1: System.out.println("num = " +num); num += 2; case 2: System.out.println("num = " + ++num); break; case 3: System.out.println("num = " +num); break; } } } A. 输出:Default num = 1 num = 3 B. 输出:Default C. 输出:Default num = 1 num = 4 D. 程序编译出错 30) 在Java中,以下程序编译运行后的输出结果为( )。 public static void main(String[] args) { int a = 5; int s = 0; switch (a) { case 5: s = s + 2; case 3: s = s + 5; case 8: s = s + 6; default: s = s + 10; break; } System.out.print(s); } A. 2 B. 0 C. 7 D. 23
展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传
相似文档                                   自信AI助手自信AI助手

当前位置:首页 > 通信科技 > 开发语言

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2025 宁波自信网络信息技术有限公司  版权所有

客服电话:4009-655-100  投诉/维权电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :gzh.png    weibo.png    LOFTER.png 

客服