What is the output of the following code?

int x = 0;
if (x < 4) {
x = x + 1;
}
System.out.println("x is " + x);

a. x is 0
b. x is 1
c. x is 2
d. x is 3
e. x is 4

b Since x is 0 before the if statement, x < 4 is ture, x becomes 1 after the statement x = x + 1 . The correct answer is B.

Computer Science & Information Technology

You might also like to view...

If the line:

friend class A; appears in class B, and the line: friend class B; appears in class C, then: a. Class A is a friend of class C. b. Class A can access private variables of class B. c. Class C can call class A’s private member functions. d. Class B can access class A’s private variables.

Computer Science & Information Technology

The number of calls to recursively calculate the Fibonacci value of 7 is:

a. 7 b. 13 c. 41 d. 39

Computer Science & Information Technology