139k views
0 votes
What is the output of the program segment below?

boolean qwerty = true;
System.out.println(qwerty);
qwerty = false;
System.out.println(qwerty);
(A) TRUE
FALSE
(B) true
false
(C) 1
0
(D) 0
1

1 Answer

5 votes

Final answer:

The Java code snippet changes a boolean variable's value from true to false and prints it. The output will be 'true' followed by 'false' on separate lines.

Step-by-step explanation:

The segment of program provided is a Java code snippet that changes the value of a boolean variable and prints it to the console both before and after the change. At the beginning, qwerty is set to true, and then printed, which will output the string "true". The variable is then set to false and printed again, which outputs the string "false". Therefore, the console will display:

true
false

The correct answer to what the output of this program segment will be is (B) true false.

User HappyPy
by
8.3k points