Analyze the following code:

boolean even = false;
if (even = true) {
System.out.println("It is even");
}

a. The program has a compile error.
b. The program has a runtime error.
c. The program runs fine, but displays nothing.
d. The program runs fine and displays It is even.


d It is a common mistake to use the = operator in the condition test. What happens is that true is assigned to even when you write even = true. So even is true. The program compiles and runs fine and displays "It is even".

Computer Science & Information Technology

You might also like to view...

Some of the changes in this workshop will only take effect once the database or database object has been ________

A) shared B) closed and reopened C) secured D) copied

Computer Science & Information Technology

A group of files can be compressed into one file

Indicate whether the statement is true or false

Computer Science & Information Technology

The latest version of NetWare is version ____________________.

Fill in the blank(s) with the appropriate word(s).

Computer Science & Information Technology

Which of the following operators are right-associative.

a. * b. + (binary +) c. % d. && e. =

Computer Science & Information Technology