




已阅读5页,还剩16页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1.若一个Java源文件包含名为Example的public类,为了成功编译该源文件,必须满足的条件是 (1) 。CA. 源文件必须具有package包语句 B. 源文件必须声明一个main方法 C. 源文件名必须为Example.java D. 源文件必须引入java.lang包2. 下述字符组合能作为Java程序标识符的是 (2) 。DAAa12 B大x Cy小 D5x3. 假设变量a、b、c均已声明为int类型且已赋不同的初值,如果正确实现将变量a和变量b的值交换,应采用下面4个程序段中的 (3) 。BA. a=b; b=a; B. c=a; a=b; b=c; C. a=c; b=a; c=a; D. b=a; a=c; c=b4. 字符型数据对应整数的取值范围是 (4) 。B A.02的16次方 B. 02的16次方-1 C. 02的15次方 D. 02的15次方-15. 若已定义数组byte x = 1, 2, -3, 4和变量“int k = 4”,下列选项中对x数组元素错误的引用是 (5) 。BA: x5-k B: xk C: xk-4 D: x7-k6. 本题所列的选项中, (6) 是正确的方法声明。DA. void m() throw IOExceptionB. void m() throw IOExceptionC. m() throws IOException4D. void m() throws IOException7. 设已有声明“int i = 0, j = 0; ”, 以下表达式中 (7) 在执行期间不会出现异常。A A. (i != 0) & (j/i= =1) B. (i != 0) & (j/i= =1) C. (i != 0) | (j/i= =1) D. (i != 0) | (j/i= =1)8. 以下关于修饰词的叙述中正确的是 AD 。D A.若源程序文件中存在import语句,则必须放置在所有非注释语句之前 B. private 成员变量可以被同一包中的所有类访问 C. 一个anstract类可以被声明为final类 D. 方法内定义的局部变量不能声明为static变量9. 要将BufferedOutputStream对象的缓冲区清空,应使用下列方法中的 (9) 。A A. flush() B. close() C.write(int b) D. reset()10. 设Tree为已定义的类名,下列语句中能正确创建Tree类对象的是 (10) 。A A. Tree t = new Tree() B. Tree t = Tree()C. Tree t = new Treeclass() D. t Tree11. 以下选项中,可正确声明一个整形变量的是 (11) AA. int $x B. int 123C. int #div D. int %percent12. 对于本题程序,以下关于编译、运行情况的叙述中正确的是 (12) D public class TestS6 public static void main(String args) int i = 012, j = 034, k = 056, m = 078; System.out.println(i); System.out.println(k); System.out.println(j); A. 输出123456 B.输出2468112 C.输出102846 D. 编译失败13.对于本题程序,以下关于编译、运行情况的叙述中正确的是 (13) 。B public class TestS3 static int myarg = 1; Public static void main(String args) int myarg = 1; System.out.println(myarg); A. 输出0 B. 输出1 C. 由于局部变量与静态变量同名,编译失败 D. 由于局部变量未初始化,编译失败14. 对于本题程序,以下关于编译、运行情况的叙述中正确的是 (14) B public class TestS4public static void main(String args) int i = new int5; System.out.println(i5); A.编译失败 B. 运行时出错 C. 输出0 D. 输出null15.运行本题程序,产生的输出是 (15) D public class TestS5public static void main(String args) Integer i = new Integer(10); Integer j = new Integer(10); System.out.print(i = j); System.out.println(“” + i.equals(j); A. false falseB. true true C. true falseD. false true16. 设某类中已存在方法 void find(int x), 以下选项中不能作为这个方法重载的是 (16) A(1) float find2(float x) (2) int find(int x) (3) double find(int x,int y) (4) void find(double y)A. (1)(2) B. (2)(3) C. (3)(4) D. (1)(4)17.以下选项中不合法的数组声明是 (17) 。BA .short x; B. short5 x; C. short y; D. short z18. 若func()的方法体内抛出IOException异常而又未处理异常,该方法声明的头部可以是 (18 ) DA. public int func(int i)B. public int func(int i) throw IOException C. public int func(int i) throw ExceptionD. public int func(int i) throws IOException19. 在FileInputStream类的构造方法中,不可以使用 (19) 类的对象来作为参数。B()()9()AInputStream B. File C. FileOutputStreamD. StringBuffer(个人觉得应该是不可以使用)20. 在小应用程序中(applet)中,若未声明 paint方法,而又使用了该方法,则该方法的参数类型是 (20) AA. Graphics B. FontC. String D. Color本题程序段执行后,产生的输出是 (1) 。D String s=new String(“abcdefg”); For(int i=1;i0) if(a3) c=2; else c=3; else c=4;A. 4 B. 3 C. 2 D. 14. 运行本题程序时,输入12345并回车,产生的输出是 (4) 。C import java.io.*; public class AS24 public static void main(String args) throws IOException BufferedReader buf = new BufferedReader(new InputStreamReader(System.in); String str= buf.readLine(); int x=Integer.parseInt(str); System.out.println(x/100); A. 45 B. 5 C. 123 D.123455. 若对本题程序进行编译运行,将出现什么情况 (5) 。C public class AS25 public static void main(String args) AS25 a = new AS25();method(8);method(1.2f); void method(float i) System.out.print(“float:”+i+” “); static void method(long i) System.out.print(“long:”+ i + “ “);A: 编译出错,两个method()方法必须定义为静态(static)方法。B: 编译出错,在同一个类中不允许两个同名的方法。C: 编译成功,运行输出为:long:8 float:1.2D: 编译成功,运行输出为:float:1.2 long:86. 下面四个main()方法的声明中不正确的是 (6) 。BA. public static void main(String args) B. public static void main(String) C. public static void main(String args) D. public static void main(String x) 7. 本题程序是一方法声明,其中MyException是一个已声明的异常类。所给选项中只有 (7) 加入【1】行后,该程序才是正确的方法声明。/B【1】【2】 int success = 15%2;【3】 if(success = 1) throw new MyException(“a bug”);【4】 A. public void method()B. public void method() throws ExceptionC. public void method throw MyExceptionD. public throw MyException void method() 8. 设4个 int型变量a1,a2,a3,a4的初值均已设置为0,以下选项中正确的赋值语句是 (8) 。D A. a1 = 15 % 2.5; B. a2 = 038; C. a3 = a1 + a2 = 39; D. a4 = 0xa2;9. 下列所给选项中, (9) 是Java类库中用于编写绘图程序的基础类。A A. Graphics B.Graphic C. Paint D. Paints10. 对于本题程序,若将private int m 改为 (10) ,则可使方法fun()直接访问成员变量m。 C class AS30 private int m; public static void fun() System.out.println(m); A. protected int m B. public int mC. static int m C. int m11. 下列选项中,不属于字符型常量的是 (11) 。BA. A B. “B”C. n D. 12212. 本题程序段执行后,产生的输出是 (12) 。A int x = 122, 33, 55, 678, -987; int max = x0; for(int i = 1; i max) max = xi; System.out.println(max);A. 678 B. 122 C. -987 D. 3313.为使以下程序段能通过编译,必须将 (13) C插入第七行的头部 class Person String name,department; int age; public Person(String n) name=n; public Person(String n, int a)name = n; age = a; public Person(String n, String d, int a) /第七行 department = d; A. Person(n,a) B.this(Person(n,a) C. this(n,a) D. this(name,age)14. 本题程序段执行后产生的输出结果是 (14) 。A int b 1,2,3, 4,5, 6,7; int sum = 0; for(int i = 0; ib.length; i+) for(int j = 0; j bi.lenght; j+) sum += bij; System.out.println(sum);A. 28 B. 6 C. 9 D. 1315.下列for语句循环体的执行次数是 (15) 。A for(int x = 0,y = 0; (y != 0) & (x 0) if(a%i =0) break ;/break i-; System.out.println(a + “的最大真约数为:” + i ); 4. 本题程序执行后, 产生的输出为 edcba 。/edcba class TestString void print(String str, int i) if(i str.length() print(str,i + 1) ; System.out.print(str.charAt(i); public static void main(String args) (new TestString().print(“abcde”, 0); 5. 本题程序接收用户从键盘输入的字符并保存在变量c中。 填充程序中的空格,实现程序的功能。 import java.io.* ;/import java.io.*; public class SimpleCharInOut public static void main(String args) char c = ; System.out.println(“Enter a character please: ”); try c = new BufferedReader(new InputStreamReader(System.in).readLine(); ;/ (char)System.in.read() catch(IOException e) System.out.println(“Youve entered character ”+ c) ; 6. 方法netFile 将统一资源定位器URL中的字符文件内容显示到屏幕。 填充程序中的空格,实现程序的功能。 static void netFile(String url) try URL ur = new URL(ur1) ;/new URL(url) int ch; InputStreamReader isr; isr = new InputStreamReader( ur.openStream ) ;/u; while(ch = isr.read() != -1) System.out.print(char)ch) ; isr.close(); catch(MalformedURLException e) catch(IOException e) 7. 本题程序输出字符串的长度及每一个位置上的字符。填充程序中的空格,实现程序的功能。 public class Z6 public static void main(String args ) String str = “GoodMorning”; int size = str.length() ;/str.length() System.out.println(“str的长度为” + size); for(int m=0; mj) if(+m = -k) k+; else k-; 10. 本题程序执行后,输出的第一行是 10 , 第二行是 16 。/10 16 class Three int a, b, c; Three(int i, int j, int k) a = i; b = j; c = k; public int sum( ) return a + b +c; class TestThree static void proc(Three t) t.a = t.a + t.b; t.b = t.b + t.c; t.c = t.c 1; public static void main(String args) Three obj = new Three(1,2,3); proc(obj); System.out.println(obj.sum(); proc(obj); System.out.println(obj.sum(); 11. 本题程序执行后,输出的第一行是 3 ,第二行是 5 。/3 5 class Z9 static int f(int x) int s = 0; for(int j = 2; j = x; j+) if(x%j = 0) x /= j;s += j; return s; public static void main(String args) for(int i = 3; i20; i+) if(i =f(i) System.out.println(i); 12. 本题程序执行后的输出是 2 。/2 class Scope int k; Scope(int k)this.k = k; void mt(int k)k = k +3; public static void main(String args) int k = 2;Scope s = new Scope(7);s.mt(k);System.out.println(k); 13. 为使本题程序通过编译,必须将其中的type改为 double 。/double public class ReturnIt type methodA(byte x, double y) return (short)x/y * 2 14. 如果一个两位整数是质数(即素数),且将组成它的两个数字交换位置后形成的整数仍为质数,则称这样的数为“绝对质数”。例如,13就是一个绝对质数。本题程序找出所有的绝对质数。填充程序中的空格,实现程序的功能。 public class Z12 public static void main(String args) for(int i = 10; i 100; i+) if(doublePrime(i) System.out.println(i); static boolean doublePrime(int n) int m = new int2; boolean flag = true; m0 = n; m1 = n%10*10+n/10 ;/n%10*10+n/10 loop:for(int j = 0;j =2; k-) if(mj%k = 0) flag=false ;/flag=false break loop; return flag; 15. 本题程序执行后,输出的第一行是 aaa ,第二行是 bbb 。 class Test0615 /aaa bbb static void m(int a) System.out.println(a3); public static void main(String args) try int b = 2,3,4;m(b);System.out.println(“*”); catch(RuntimeException ex) System.out.println(“aaa”); System.out.println(“bbb”) 16. 本题程序是一个方法coordinate,其功能是在数组a的基础上返回一个新数组,新数组与数组a的长多相同,新数组的前部存放a中的负值元素,后部存放a中的非负值元素。试填充程序中的空格,实现程序功能。 int coordinate(int a) int b = new inta.length; /int int ida = 0, idbf = 0;int idbb = a.length-1 ; /b.length-1while(ida a.length) if(aida 0) bidbf = aida; idbf+; else bidbb = aida; idbb-; ida+ ; /ida+ 1. 假设已有定义 byte a = 4; short b = 5; 则表达式(a+b)的结果类型为 short 型。(int)2. 运行本题程序,产生的输出是 3020 。(30 20) class Z1 public static void main( String args) int m = 10, n = 20; System.out.println(m + n + ” ” +n) ; 3. 运行本题程序,产生的输出是 x=81,n=4 。/n= 4) public class TestF12 public static void main(String args) int
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025安徽宿州市立医院招聘编外人员42人考前自测高频考点模拟试题附答案详解(典型题)
- HLX26-生命科学试剂-MCE
- 2025江苏盐城工学院招聘专职辅导员13人模拟试卷含答案详解
- 2025年激光扫瞄显微镜项目发展计划
- 2025年长城钻探工程公司春季招聘(20人)考前自测高频考点模拟试题及答案详解参考
- 房产买卖协议表
- 广州课件配音服务平台
- 2025年吡咯并吡咯二酮类项目建议书
- 2025湖北武汉市通城县事业单位高层次和急需紧缺人才引进48人考前自测高频考点模拟试题及答案详解(夺冠系列)
- 美妆行业全球市场健康美肤潮流趋势
- 2025广东珠海市下半年市直机关事业单位招聘合同制职员37人考试参考试题及答案解析
- 软件开发驻场合同协议
- 矿山承包法律合同范本
- 音乐培训机构招生
- 时文语法填空-电影篇 《731》 《长安的荔枝》 《戏台》
- 主题一 2. 设计节电方案(课件) 综合实践活动教科版五年级上册
- 生产成本控制及预算管理表格模板
- 2025年家庭健康管理师考试模拟题及答案
- 山东省青岛市即墨区实验学校2025-2026学年九年级上学期开学考试英语试题(含答案)
- 浙江省浙南名校联盟2025-2026学年高二上学期开学返校联考英语试卷(含音频)
- 关于鼓励员工考取各类资格证书的管理办法
评论
0/150
提交评论