JAVA试卷2

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
for (i=0, j=1; i<=j+1; j--) { i = i + 2;
} A. 3 B. 2 C. 1 D. 0 18、关于下面代码片段,说法正确的是()。
int a = 8, b = 9; if (a = b){
System.out.println("true"); }else{
System.out.println("false"); } A. 输出 true B. 输入 false C. 无输出 D. 编译错误 19、下面程序中,while 循环的循环次数是()。 public static void main(String[ ] args){
A. 代码成功编译,运行后打印 “A,B”.
B. 代码成功编译,运行后打印“A,A”.
C. 代码成功编译,运行后打印“B,B”.
D. 代码成功编译,运行后打印“AB,B”.
E. 代码成功编译,运行后打印“AB,AB”.
F. 代码没有编译成功因为 “+” 没有被 StringBuffer 重载.
10、阅读代码片段,下面()代码导致程序出错。
public static void main(String args[ ]){
int n;
double s;
s=1.0;
for(n=10;n>1;n--){
s=s+1/n;
}
System.out.println(s);
}
}
程序运行后,输出结果错误,导致程序出错的是()。
A. s = 1.0
B. for(n=10;n>1;n--)
case 1:
System.out.println("Test1");
case 2:
case 3:
System.out.println("Test2");
break;
case 4:
System.out.println("Test3");
break;
}
A. 0
B. 1
C. 2
D. 3
3、 下面()正确创建包含 5 个""字符串的数组。
if(val > 4){ System.out.println("Test A");
}else if(val > 9){ System.out.println("Test B");
}else { System.out.println("Test C");
} A. val = 0 输出“Test C” B. val 介于 0 到 4 之间输出“Test C” C. val = 14 输出“Test B” D. val = 5 输出“Test A” 7. 代码如下: 3. string foo = “ABCDE”; 4. foo.substring(3); 5. foo.concat(“XYZ”); 6. 写出 foo 在第 6 行是什么. 8. 代码如下: 1. Public class test ( 2. Public static void stringReplace (String text) ( 3. text = text.replace (‘j’ , ‘i’); 4. ) 5. 6. public static void bufferReplace (StringBuffer text) ( 7. text = text.append (“C”) 8. ) 9. 10. public static void main (String args[]) ( 11. String textString = new String (“java”); 12. StringBuffer textBuffer = new StringBuffer (“java”); 13. 14. stringReplace (textString); 15. BufferReplace (textBuffer); 16. 17. System.out.printIn (textString + textBuffer); 18. ) 19. ) 输出是什么?
//省略代码 } A. import java.util.*; B. package com.mypackage; C. int a = 1; D. 以上都不对 16、下列()中 main 方法可以作为应用程序入口。 A. public void main(String[ ] args){ //程序主体} B. public static void main(){ //程序主体} C. public static void main(String[ ] a){ //程序主体} D. public static void main(String args){ //程序主体} 17、以下循环体的执行次数是()。 int i, j;
int i = 0; while(i<10){
if(i<1){ continue;
}
if(i==5) {
break;
}
i++;
}
}
A. 1 B. 10
C. 6 D. 死循环
20、关于下面代码,说法正确的是()。
1. public class Test {
2.
public static void main(String[ ] args1){
int x=8,a=1; do{
a=a+1; } while (x>0); } } A. 0 B. 1 C. 无限次 D. 有限次 13、声明 s1, String s1 = new String("phenobarbital"); 经过下面代码之后, String s2 = s1.substring(3, 5); s2 的值是()。 A. null B. "eno" C. "enoba" D. "no" 14、下面代码输出结果是()。 int i=0,s=0; do{ if(i%2==0){
B. 第 7 行有编译错误
C. 第 11 行有编译错误
D. 运行输出 11
E. 运行输出 12
21、运行下面这段代码,输出结果是()。
public class MyTest {
int x = 30;
public static void main(String args[]){
int x = 20;
MyTest ta = new MyTest();
D. package、class、import
24、下面()不是 String 对象合法的方法。
A. equals(String)
B. trim()
C. append()
t = t + " FRIEND";
sb.append(t);
System.out.println(sb.toString().toLowerCase());
A. my friend hello
B. Hello MY FRIEND
C. MY FRIEND Hello
D. hello my friend
3.
Test test = new Test();
4.
int x = 10;
5.
if (test.methodA()){
6.
x++;
7.
System.out.println(x);
8.
}
9.
}
10. public int methodA(){
11.
return 10;
12. }
13. }
A. 第 5 行有编译错误
C. s = s + 1 /n D. System.out.println(s);
23、在一个 Java 文件中,使用 import、class 和 package 的正确顺序是()。
A. package、import、class
B. class、import、package
C. import、package、class
5、下面代码片段创建()个对象。
int a = 10;
String b = "abc";
String c = new String("abc");
百度文库
E. 4
MyTest test = new MyTest(); A. 4 B. 3 C. 2 D. 1 6、假设 val 是整型变量,下面()说法不正确。
switchCoords(x,y);
System.out.print("(" + x + ", " + y + ")");
}
public void switchCoords(int x,int y){
int temp;
temp = x;
x = y; y = temp; System.out.print("(" + x + ", " + y + ")"); } } A. (5,3)(3,5)(3,5) B. (5,3)(5,3)(5,3) C. (5,3)(3,5)(5,3) D. 编译出错 12、有下面程序,语句 a=a+1 执行的次数是()。 public class Test { public static void main(String[ ] args){
ta.Method(x);
System.out.println(x);
}
public void Method(int y){
int x = y * y;
}
}
A. 30 B. 400
C. 900 D. 20
22、要求以下程序的功能是计算:
s=1+1/2+1/3+…+1/10=2.9289682…
public class MyTest {
C. 第 3 行
D. 第 4 行
E. 第 7 行
11、阅读下面代码,myMethod 被调用时,正确的输出结果是()。
public class MyPoint {
public void myMehtod() {
int x = 5, y= 3;
System.out.print("(" + x + ", " + y + ")");
一 . 选择题(每题 2 分)
1、下面()是合法的 Java 变量名。
A. _myString
B. $a+b
C. myString
D. 9myString
2、阅读下列代码,i 值为()时输出结果中不包括“Test2”。
switch(i){
default: System.out.println("无匹配");
5. operate (a,b);
6. system.out.printIn{a + “,” +b};
7. }
8. static void operate (StringBuffer x, StringBuffer y) {
9. x.append {y};
10. y = x;
11. }
12. }
哪个是正确答案?
A. String[ ] a = new String[5];
for(int i=0 ; i< 5;i++ ){
a[i]="";
}
B. String a[ ] = new String[ ] ;
a = {"","","","",""};
C. String[ ] a = {"","","","",""};
int count;
//第 1 行
int x[ ] = new int[10];
//第 2 行
for(int i = 0; i < 5){
//第 3 行
count++;
//第 4 行
i++;
//第 5 行
}
//第 6 行
System.out.println(x[5]);
A. 第 1 行
B. 第 2 行
i++; continue; } i++; s = s + i; }while(i<7); System.out.println(s);
A. 16
B. 12 C. 28 D. 21 15、A.java 文件包含下面的程序片段,()放到“//添加 代码”处,程序仍可以正常运行。
//添加代码 public class A {
9 . 代码如下:
1. public class Foo {
2. public static void main (String [] args) {
3. StringBuffer a = new StringBuffer (“A”);
4. StringBuffer b = new StringBuffer (“B”);
D. String a[ ] = new String[5] {"","","","",""};
E. String a[5] = {"","","","",""};
4、 阅读下面代码片段,输出结果是()。
StringBuffer sb = new StringBuffer("Hello");
String t = " MY";
相关文档
最新文档