Basic Java Quiz

成绩: 72.5分

一、单选题 (题数:40,共 100.0 分)
13.6 Q5: Which of the following statements is true?(2.5分)0.0 分
A、
Both syntax errors and logic errors are caught by the compiler.
B、
Both syntax errors and logic errors have effects at execution time.
C、
Syntax errors are caught by the compiler. Logic errors have effects at execution time.
D、
Logic errors are caught by the compiler. Syntax errors have effects at execution time.
正确答案: C 我的答案:B
答案解析:

24.8 Q2: {Suppose variable gender contains MALE and age equals 60, how is the expression
(gender == FEMALE) && (age >= 65)
evaluated?
}(2.5分)0.0 分
A、
The condition (gender == FEMALE) is evaluated first and the evaluation stops immediately.
B、
The condition (age >= 65) is evaluated first and the evaluation stops immediately.
C、
Both conditions are evaluated, from left to right.
D、
Both conditions are evaluated, from right to left.
正确答案: A 我的答案:C
答案解析:

3
Q1: What is output by the following Java code segment?

int temp = 180;

while (temp != 80)

{

if (temp > 90)

{

  System.out.print("This porridge is too hot! ");



  // cool down

  temp = temp – (temp > 150 ? 100 : 20);

}

else

{

  if (temp < 70)

  {

     System.out.print(

        "This porridge is too cold! ");

 

        // warm up

        temp = temp + (temp < 50 ? 30 : 20);

  }

}

}

if (temp == 80)

System.out.println(“This porridge is just right!”);

(2.5分)2.5 分
A、
This porridge is too cold! This porridge is just right!

B、
This porridge is too hot! This porridge is just right!

C、
This porridge is just right!

D、
None of the above.

正确答案: B 我的答案:B
43.9 Q1: Which of the following terms is not used to refer to a sentinel value that breaks out of a while loop?(2.5分)0.0 分
A、
signal value.
B、
maximum value.
C、
dummy value.
D、
flag value.
正确答案: B 我的答案:C
答案解析:

53.9 Q2: Sentinel-controlled repetition is also known as ________.(2.5分)2.5 分
A、
Definite repetition
B、
Indefinite repetition
C、
Multiple repetition
D、
Double repetition
正确答案: B 我的答案:B
答案解析:

63.4 Q5: Which of the following is a double-selection control statement?(2.5分)2.5 分
A、
do…while
B、
for
C、
if…else
D、
if
正确答案: C 我的答案:C
答案解析:

7
Q2: What is output by the following Java code segment?

int temp = 180;

if (temp > 90)

{

System.out.println(“This porridge is too hot.”);

// cool down

temp = temp – (temp > 150 ? 100 : 20);

}

else

{

if (temp < 70)

{

  System.out.println("This porridge is too cold.");

 

  // warm up

  temp = temp + (temp < 50 ? 30 : 20);

}

}

if (temp == 80)

System.out.println(“This porridge is just right!”);

}

(2.5分)2.5 分
A、
This porridge is too hot.

B、
{This porridge is too cold.
This porridge is just right! }

C、
This porridge is just right!

D、
None of the above.

正确答案: D 我的答案:D
83.6 Q3: Which of the following would not be used to clarify a dangling-else?(2.5分)0.0 分
A、
Indentation.
B、
Parentheses ().
C、
Braces {}.
D、
Comment //.
正确答案: B 我的答案:C
答案解析:

9
Q1: Consider the following two Java code segments:

Segment 1 Segment 2

int i = 0;

                                                                        for (int i = 0; i <= 20; i++)

while (i < 20) {

{ System.out.println(i);

i++; }

System.out.println(i);

}

Which of the following statements are true?

(2.5分)2.5 分
A、
The output from these segments is not the same.

B、
The scope of the control variable i is different for the two segments.

C、
Both (a) and (b) are true.

D、
Neither (a) nor (b) is true.

正确答案: C 我的答案:C
103.6 Q1: Which of the following statements about the conditional operator (?😃 is false?(2.5分)2.5 分
A、
The conditional operator is a ternary operator, meaning that it takes three operands.
B、
The first operand is a boolean expression.
C、
The second operand is the result value if the condition evaluates to false.
D、
The second operand is the result value if the condition evaluates to true.
正确答案: C 我的答案:C
答案解析:

114.5 Q2: Which of the following will not help prevent infinite loops?(2.5分)0.0 分
A、
Include braces around the statements in a do…while statement.
B、
Ensure that the header of a for or while statement is not followed by a semicolon.
C、
If the loop is counter-controlled, the body of the loop should increment or decrement the counter as needed.
D、
If the loop is sentinel-controlled, ensure that the sentinel value is input eventually.
正确答案: A 我的答案:D
答案解析:

124.4 Q4: Which statement prints the floating-point value 123.456 right justified with a field width of 10?(2.5分)2.5 分
A、
System.out.printf("%d10.3", 123.456);
B、
System.out.printf("%10.3d", 123.456);
C、
System.out.printf("%f10.3", 123.456);
D、
System.out.printf("%10.3f", 123.456);
正确答案: D 我的答案:D
答案解析:

13
Q5: boolean values can be displayed as the words true and false with the ________ format specifier.

(2.5分)0.0 分
A、
%bool.

B、
%b.

C、
%true.

D、
%boolean.

正确答案: B 我的答案:D
14
Q2:{ For the code segment below:

switch(q)

  {

     case 1:

        System.out.println("apple");

        break;

     case 2:

        System.out.println("orange");

        break;

     case 3:

        System.out.println("banana");

        break;

case 4:

        System.out.println("pear");

     case 5:

        System.out.println("grapes");

     default:

        System.out.println("kiwi");

  }

Which of the following values for q will result in kiwi being included in the output?
}

(2.5分)2.5 分
A、
2.

B、
Any integer less than 1 and greater than or equal to 4.

C、
1.

D、
3.

正确答案: B 我的答案:B
153.6 Q4: The empty statement is denoted by what symbol?(2.5分)0.0 分
A、
Semicolon ;
B、
Parentheses ()
C、
Braces {}
D、
Colon :
正确答案: A 我的答案:D
答案解析:

163.9 Q6: Which of the following statements is false?(2.5分)2.5 分
A、
To ensure that the operands in a mixed-type expression are of the same type, Java performs implicit conversion on selected operands.
B、
Cast operators are unary operators.
C、
Cast operators associate from right to left and are one level lower in precedence than the multiplicative operators.
D、
Cast operators are formed by placing parentheses around the name of a type.
正确答案: C 我的答案:C
答案解析:

173.11 Q2: What does the expression x %= 10 do?(2.5分)2.5 分
A、
Adds 10 to the value of x, and stores the result in x.
B、
Divides x by 10 and stores the remainder in x.
C、
Divides x by 10 and stores the integer result in x.
D、
None of the above.
正确答案: B 我的答案:B
答案解析:

183.7 Q3: In an activity diagram, the merge symbol has the same shape as what other symbol?(2.5分)2.5 分
A、
Decision symbol.
B、
Action symbol.
C、
Transition arrows.
D、
Initial state.
正确答案: A 我的答案:A
答案解析:

193.8 Q1: Counter-controlled repetition is also known as:(2.5分)2.5 分
A、
Definite repetition
B、
Indefinite repetition
C、
Multiple-repetition structure
D、
Double-repetition structure
正确答案: A 我的答案:A
答案解析:

204.9 Q2: Which of the following is not a type of repetition statement in Java?(2.5分)2.5 分
A、
while statement.
B、
do…while statement.
C、
for statement.
D、
loop statement.
正确答案: D 我的答案:D
答案解析:

213.4 Q6: Which of the following is not a Java keyword?(2.5分)2.5 分
A、
do
B、
next
C、
while
D、
for
正确答案: B 我的答案:B
答案解析:

224.4 Q2: Which of the following will count down from 10 to 1 correctly?(2.5分)0.0 分
A、
for (int j = 10; j <= 1; j++)
B、
for (int j = 1; j <= 10; j++)
C、
for (int j = 10; j > 1; j–)
D、
for (int j = 10; j >= 1; j–)
正确答案: D 我的答案:C
答案解析:

23
Q1:{ For the two code segments below:

Segment A

   int q = 5;

switch(q)

{

case 1:

System.out.println(1);

case 2:

System.out.println(2);

case 3:

System.out.println(3);

case 4:

System.out.println(4);

case 5:

System.out.println(5);

default:

System.out.println(“default”);

}

Segment B

q = 4;

switch(q)

{

case 1:

   System.out.println(1);

case 2:

   System.out.println(2);

case 3:

   System.out.println(3);

case 4:

   System.out.println(4);

case 5:

   System.out.println(5);

default:

   System.out.println("default");

}

Which of the following statements is true?
}

(2.5分)2.5 分
A、
{The output for Segment A is:
default}

B、
{The output for Segment B is:
4}

C、
{The output for Segment B is:
45default}

D、
{The output for Segment A is:
5
default}

正确答案: D 我的答案:D
243.8 Q3: Where can local variables declared within a method’s body be used?(2.5分)2.5 分
A、
Only in that method between the line in which they were declared and the closing brace of that method.
B、
Same as (a), but not within while or if statements.
C、
Only within while or if statements within the method in which they were declared.
D、
Anywhere within the class.
正确答案: A 我的答案:A
答案解析:

254.7 Q3: To exit out of a loop completely, and resume the flow of control at the next statement after the loop, use a _______.(2.5分)0.0 分
A、
continue statement.
B、
break statement.
C、
return statement.
D、
Any of the above.
正确答案: B 我的答案:C
答案解析:

263.13 Q3: Which primitive type can hold the largest value?(2.5分)2.5 分
A、
int
B、
long
C、
float
D、
double
正确答案: D 我的答案:D
答案解析:

273.7 Q2: Which of the following is not an error (either a syntax error or a logic error)?(2.5分)2.5 分
A、
Neglecting to include an action in the body of a while statement that will eventually cause the condition to become false.
B、
Spelling a keyword (such as while or if) with a capitalized first letter.
C、
Using a condition for a while statement that is initially false.
D、
An infinite loop.
正确答案: C 我的答案:C
答案解析:

28
4.6 Q3: Which of the following can be used in a switch statement in the expression after keyword case?

a.a constant integral expression.

b.a character constant.

c.a String

d.an enumeration constant.

(2.5分)0.0 分
A、

a and b.

B、
a and c

C、
b and c

D、

All.

正确答案: D 我的答案:B
29
Q1: Consider the code segment below.

if (gender == 1)
{

if (age >= 65)

  ++seniorFemales;

}

This segment is equivalent to which of the following?

(2.5分)2.5 分
A、
{if (gender == 1 || age >= 65)
++seniorFemales;}

B、
{if (gender == 1 && age >= 65)
++seniorFemales; }

C、
{if (gender == 1 AND age >= 65)
++seniorFemales; }

D、
{if (gender == 1 OR age >= 65)
++seniorFemales; }

正确答案: B 我的答案:B
答案解析:

30Q5: Which formatting flag indicates that the floating-point values should be output with a thousands separator?(2.5分)0.0 分
A、
plus (+).
B、
minus (-).
C、
comma (,).
D、
period (.).
正确答案: C 我的答案:D
答案解析:

312.5.2 Q1: The filename for the public class that begins with public class Addition must be(2.5分)2.5 分
A、
public.java.
B、
public.class.java.
C、
Addition.java.
D、
addition.java.
正确答案: C 我的答案:C
322.5.8 Q1: Portions of statements that contain calculations are called(2.5分)2.5 分
A、
variables.
B、
constants.
C、
expressions.
D、
None of the above.
正确答案: C 我的答案:C
332.3 Q5: Which of the following statements would display the phase Java is fun?(2.5分)2.5 分
A、
System.out.println( "hellois fun\rJava " );
B、
System.out.println( ‘Java is fun’ );
C、
System.out.println( ““Java is fun”” );
D、
System.out.println( Java is fun );
正确答案: A 我的答案:A
342.6 Q1: Which of the following statements does not alter the value stored in a memory location?(2.5分)2.5 分
A、
int a;
B、
number = 12;
C、
y = y + 2;
D、
width = Integer.parseInt(input);
正确答案: A 我的答案:A
352.2 Q2: Which of the following is not a valid Java identifier?(2.5分)2.5 分
A、
my Value
B、
$_AAA1
C、
width
D、
m_x
正确答案: A 我的答案:A
答案解析:

362.3 Q2: Which of the following is the escape character?(2.5分)2.5 分
A、
*
B、

C、
\n
D、
"
正确答案: B 我的答案:B
372.5.6 Q1: Which of the following is a Scanner method for inputting an integer value?(2.5分)2.5 分
A、
nextInteger
B、
integer
C、
nextInt
D、
int
正确答案: C 我的答案:C
382.2 Q5: Which command compiles the Java source code file Welcome.java?(2.5分)2.5 分
A、
cd Welcome.java
B、
javac Welcome.java
C、
java Welcome.java
D、
compile Welcome.java
正确答案: B 我的答案:B
392.4 Q2: Which of the following statement displays Hello World?(2.5分)2.5 分
A、
System.out.printf( “%2s”, "Hello " “World” );
B、
System.out.printf( “%s %s”, “Hello”, “World” );
C、
System.out.printf( “%s%s”, “Hello, World” );
D、
System.out.printf( “s% s%”, “Hello”, “World” );
正确答案: B 我的答案:B
402.5.1 Q1: All import declarations must be placed(2.5分)2.5 分
A、
inside the class declaration’s body.
B、
before the class declaration.
C、
after the class declaration.
D、
all of the above will work.
正确答案: B 我的答案:B

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值