QUESTION 1 In Java, the symbol “=” and the symbol “==” are used synonymously (interchangeably).

True

False

QUESTION 2 Given the following code, where x = 0, what is the resulting value of x after the for-loop terminates?

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

x += i;

A.0B.4C.5D.10

QUESTION 3 The following loop is syntactically valid.

for (int j = 0; j < 1000; j++) j–;

True

False

QUESTION 4 It is possible to convert any type of loop (while, do, or for) into any other. True

False

QUESTION 5 If x is an int where x = 0, what will x be after the following loop terminates?

while (x < 100)

x *= 2;

2

64

100

128

none of the above, this is an infinite loop

QUESTION 6 Consider the following switch statement where x is an int. If x is currently equal to 3, what will the value of x be after the switch statement executes?

switch (x)

{

case 3 : x += 1;

case 4 : x += 2;

case 5 : x += 3;

case 6 : x++;

case 7 : x += 2;

case 8 : x–;

case 9 : x++;

}

A- 6

B- 11

C- 10

D- 12

QUESTION 7 A switch statement must have a default clause. True

False

QUESTION 8 How many times will the following loop iterate?

int x = 0;

do {

System.out.println(x);

x++;

} while (x > 0 && x<10);

A.1 timeB.9 timesC.10 timesD.11 times

QUESTION 9 Control in a switch statement jumps to the first matching case. True

False

1.5 points QUESTION 10 The following for-loop is an infinite loop.

int i; for (int j = 0; j < 1000; ) i++;

True

False

QUESTION 11 Assume that count is 0, total is 20 and max is 1. The following statement will do which of the following? if (count != 0 && total / count > max) max = total / count;

A- The condition short circuits and the assignment statement is not executed

B- The condition short circuits and the assignment statement is executed without problem

C- The condition does not short circuit causing a division by zero error

D- The condition short circuits so that there is no division by zero error when evaluating the condition, but the assignment statement causes a division by zero error

QUESTION 12 The break statement does which of the following?

A- ends the program

B- transfers control out of the current control structure such as a loop or switch statement

C- ends the current line of output, returning the cursor

D- denotes the ending of a switch statement

E- indicates the end of line when using System.out.print

QUESTION 13 The do loop differs from the while loop in that

A- the while loop will always execute the body of the loop at least once

B- the do loop will always execute the body of the loop at least once

C- the do loop will continue to loop while condition in the while statement is false and the while loop will continue to loop while the condition in the while statement is true

D- the while loop will continue to loop while condition in the while statement is false and the do loop will continue to loop while the condition in the while statement is true

E- none of the above, there is absolutely no difference between the two types of loops

QUESTION 14 Of the following if-statements, which one correctly executes three instructions if the condition is true?

if (x < 0)

a = b * 2;

y = x;

z = a – y;

{

if (x < 0)

a = b * 2;

y = x;

z = a – y;

}if { (x < 0)

a = b * 2;

y = x;

z = a – y ;

}

if (x < 0)

{

a = b * 2;

y = x;

z = a – y;

}

QUESTION 15 How many times will the following loop iterate?

int x = 0;

while (x > 0 && x<10)

{

System.out.println(x);

x++;

}

A.0 timesB.1 timeC.9 timesD.10 times

QUESTION 16 Which of the sets of statements below will add 1 to x if x is positive and subtract 1 from x if x is negative but leave x alone if x is 0?

if (x > 0) x++;

else x–;

if (x > 0) x++;

else if (x < 0) x–;

if (x > 0) x++;

if (x < 0) x–;

else x = 0;

if (x == 0) x = 0;

else x++;

x–;

E) x++;

x–; QUESTION 17 Assume that x and y are int variables with x = 5, y = 3, and a and d are char variables with a = ‘a’ and d = ‘A’, and examine the following conditions:

Condition 1: (x < y && x > 0)

Condition 2: (a != d || x != 5)

Condition 3: !(true && false)

Condition 4: (x > y || a == ‘A’ || d != ‘A’)

All 4 Conditions are true, Only Condition 2 is true, Condition 2 and Condition 4 are true only, Conditions 2, 3 and 4 are all true, Condition 1 is not, All 4 Conditions are false

QUESTION 18 You might choose to use a switch statement instead of nested if-else statements ifthe variable being tested might equal one of several hundred int valuesthe variable being tested might equal one of only a few int valuesthere are two or more int variables being tested, each of which could be one of several hundred valuesthere are two or more int variables being tested, each of which could be one of only a few valuesnone of the above, you would never choose to use a switch statement in place of nested if-else statements under any circumstance

1.5 points QUESTION 19 The statement if (a >= b) a++; else b–; will do the same thing as the statement if (a < b) b–; else a++;. True

False

QUESTION 20 Consider the following switch-statement where x is an int. If x is currently equal to 5, what will the value of x be after the switch statement executes?

switch (x)

{

case 3 : x += 1;

case 4 : x += 2;

case 5 : x += 3;

case 6 : x++;

case 7 : x += 2;

case 8 : x–;

case 9 : x++;

}

A.8B.6C.11D.5

### Looking for a Similar Assignment? Hire our Top Techical Tutors while you enjoy your free time! All papers are written from scratch and are 100% Original. Try us today! Active Discount Code FREE15