一、判断题
( T )语句 System.out.println(4+8+“Hello,world!”); 的输出结果是12Hello,world!。
( T )Java的字符类型采用的是Unicode编码,每个Unicode码占16个比特。
( T )boolean done = true; is a valid assignment statement.
( F )The following answers is the correct way to declare a Boolean variable named truth: boolean truth == true;
( T )Java的各种数据类型占用固定长度,与具体的软硬件平台环境无关。
( T )boolean型数据的值只有true和false。
( F )char of Java is 8-bit.
( F )[ ] use to delineate a block of statements in Java.
( F )Java的字符类型采用的是ASCII编码。
二、单选题
- What will be printed out if you attempt to compile and run the following code ( C )。
int i=1;
switch (i) {
case 0:System.out.println("zero");break;
case 1:System.out.println("one");
case 2:System.out.println("two");
default:System.out.println("default");
}
A. one
B. one, default
C. one, two, default
D. default
2. For the code below: What is the output( B )。
boolean m = true;
if ( m=false )
System.out.println(“False”);
else
System.out.println(“True”);
A. False
B. True
C. None
D. An error will occur when running
3. 下面的方法,当输入为2的时候返回值是多少( D )。
public int getValue(int i) {
int result = 0;
switch (i) {
case 1:
result = result + i;
case 2:
result = result + i * 2;
case 3:
result = result + i * 3;
}
return result;
}
A. 0
B. 2
C. 4
D. 10
4. 假设有如下程序:最终执行结果是什么( C )。
public class Demo {
public static void main(String args[]) {
int sum = 0 ;
int x = 10 ;
while (x > 0) {
sum += x ;
}
System.out.println(sum) ;
}
}
A. 55.0
B. 10.0
C. 程序错误,死循环
D. 55.0
5. For code below: After executing line 2, where will the program jump( D )。
int i, j;
Loop1: // 1
for ( i=0; i<20; i++ ) {
for ( j=0; j<i*i; j++ ) {
if ( j*2 ==i )
break Loop1; } // 2
i=4; // 3
}
i=5; // 4
A. 1
B. 2
C. 3
D. 4
6. 分析下列代码的运行结果是什么( A )。
void looper(){
int x=0;
one:
while(x<20) {
two:
System.out.print(++x);
if(x>3)
break two;
}
}
A. 编译错误
B. 0
C. 1
D. 2
7. 在Java中,以下程序段的输出结果是( B )。
int n=9;
while(n>6){
n--;
System.out.print(n);
}
A. 987
B. 876
C. 8765
D. 9876
8. 整型数据类型中,需要内存空间最少的是( D )。
A. short
B. long
C. int
D. byte
9. 当编译并运行下列程序段时,运行结果是什么( C )。
public class Test {
public static void main(String[ ] args) {
int i=0;
while (i--<0){
System.out.println("The value of i is "+i);
}
System.out.println("The end");
}
}
A. 编译时错误
B. 运行时错误
C. The end
D. The value of i is 0
10. What will happen when you attempt to compile and run the following code( D )。
int Output=10;
boolean b1 = false;
if((b1==true) && ((Output+=10)==20)){
System.out.println("We are equal "+Output);
} else {
System.out.println("Not equal! "+Output);
}
A. Compile error, attempting to preform binary comparison on logical data type
B. Compilation and output of “We are equal 10”
C. Compilation and output of “Not equal! 20”
D. Compilation and output of "Not equal! 10"
11. 设有变量定义: short a = 300; 则以下哪一条语句会导致编译错误( B )。
A. a += 3;
B. a = (short)a + 3;
C. a = (byte)(a + 3);
D. a = (short)(a * 100);
12. 下面哪单词是Java语言的关键字( B )。
A. Float
B. this
C. string
D. unsigned
13.当编译运行下列代码时,运行结果是什么( D )。
public class Demo{
public static void main(String args[]){
int i=012; int j=034;
int k=056;int l=078;
System.out.println(i);
System.out.println(j);
System.out.println(k); }
}
A. 输出12,34和56
B. 输出24,68和112
C. 输出10,28和46
D. 编译错误
14. MAX_LENGTH是int型public成员变量,变量值保持为常量55,用简短语句定义这个变量( D )。
A. public int MAX_LENGTH=55
B. final int MAX_LENGTH=55
C. final public int MAX_LENGTH=55
D. public final int MAX_LENGTH=55
15. 以下选项中没有语法错误的是( C )。
A. while (int i<7) {i++;System.out.println(“i is “+i);}
B. int j=3; while(j) {System.out.println(“ j is “+j);}
C. int j=0;for(int k=0; j + k !=10; j++,k++) {System.out.println(“ j is “+ j + “k is”+ k);}
D. int j=0;do{System.out.println( “j is “+j++);if (j == 3) {continue loop;}}while (j<10);
16. 下列不可作为java语言标识符的是( D )。
A. a2
B. $2
C. _2
D. 22
17. 下面代码运行结果显示( C )。
double temperature = 50;
if (temperature >= 100)
System.out.println("too hot");
else if (temperature <= 40)
System.out.println("too cold");
else
System.out.println("just right");
A. too hot
B. too cold
C. just right
D. too hot too cold just right
18. 下面代码将输出( B )行 “Welcome to Java”?。
int count = 0;
do {
System.out.println("Welcome to Java");
} while (count++ < 10);
A. 10
B. 11
C. 9
D. 1
19. 在JAVA中,给定代码片段如下所示,则编译运行后,输出结果是( B )。
for (int i = 0; i < 10; i++) {
if (i == 10 - i) {
break;
}
if (i % 3 != 0) {
continue;
}
System.out.print(i + " ");
}
A. 0
B. 0 3
C. 0 3 6
D. 0 3 6 9
20. 分析下面这段Java代码,它的运行结果是( C )。
Import java.io.*;
Public class B{
Public static void main(string [] args){
int i=12;
System.out.println(i+=i-=i*=i);
}
}
A. 100
B. 0
C. -120
D. 程序无法编译
21. 假设有如下程序:最终的执行结果是什么( A )?
public class Demo {
public static void main(String args[]) {
String str = "" ;
for (int x = 0 ; x < 5 ; x ++) {
str += x ;
}
System.out.println(str) ;
}
}
A. 01234
B. 10.0
C. 14.0
D. 25.0
22. Which statement below is incorrect: ( A )。
A. float a = 2.0
B. double b=2.0
C. int c=2
D. long d=2
23. 以下程序段的输出结果是( C )。
class Test {
public static void main(String[] args) {
System.out.println(4 + 5 + "" + 3 + 6);
}
}
A. 99
B. 4536
C. 936
D. 459
24. 下列选项中不属于本段代码输出结果的是( D )。
public class Main{
public static
这是一份包含判断题、单选题、填空题和编程题的JAVA程序设计习题集,涉及二进制运算、数据类型、条件判断、循环控制等多个核心概念,适合初学者和进阶者进行练习和测试。
最低0.47元/天 解锁文章
2018

被折叠的 条评论
为什么被折叠?



