2024年pta基础编程题答案java

pta基础编程题答案java常将有日思无日 莫待无时思有时 增广贤文 沈师 PTA JAVA 程序设计 第 2 章习题集 判断题 T 语句 System out println 4 8 Hello world 的输出结果是 12Hello world T Java 的字符类型采 的是 Unicode 编码 每个 Unicode 码占 16 个 特 T boolean done true

大家好,我是讯享网,很高兴认识大家。



常将有日思无日,莫待无时思有时。——《增广贤文》

【沈师PTA】JAVA程序设计-第2章习题集

⼀、判断题

( 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. pta基础编程题答案java

( F )Java的字符类型采⽤的是ASCII编码。

⼆、单选题

1. 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; i20; i++ ) {

小讯
上一篇 2024-12-28 07:23
下一篇 2025-01-01 16:15

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/8277.html