Exam 1z0-808 All QuestionsBrowse all questions from this exam
Question 116

Given the code fragment:

What is the result?

    Correct Answer: D

    The variable `var1` is evaluated using the ternary operator. In this case, the expression `(12_345.01 <= 123_45.00)` is false (since 12,345.01 is greater than 12,345.00), so `var1` is assigned the value `124_56.02f`. Adding 1024 to this value results in `13480.02`. Therefore, the correct result printed is 13480.02.

Discussion
EmilioDeBakuOption: C

Answer is C

RAADEL3IMLAKOption: D

Answer is D. is tested

kh_ismOption: D

Tested Correct answer is D : 13480.02

carlosworkOption: D

Answer is D. To test: public static void main(String[] args) { float var1 = (12_345.01 <= 123_45.00) ? 12_456 : 124_56.02f; float var2 = var1 + 1024; System.out.println(var2); }

UAK94Option: D

Answer is D. float var1 = (12_345.01 <= 123_45.00) ? 12_456 : 124_56.02f; float var2 = var1 + 1024; System.out.println(var2); // 13480.02

AysegulOption: B

B, if returns true so double comes. Then it couldn’t be assigned float

JongHwa

12_456 is not double but int.

Winston123

int value can assign to the float value

SSJ5Option: C

Correct answer C

pri_yaOption: C

The correct answer C, Tested 13480.0

Harid

this is a tricky question. the boolean statement is double and double doesn't fit inside the float. Looks like false/true return type matters here, not data type inside the boolean expression.

hotuyaOption: C

The answer is C Confirmed on Netbeans

sai9999Option: C

Correct answer is C

amit_lad88Option: D

Correct Answer is D float var1 = (12_345.01 <= 123_45.00) ? 12_456 : 124_56.02f; // 124_56.02f value assigned to var1 float var2 = var1 + 1024; // 124_56.02f +1024 System.out.println(var2); // 13480.02

ManuTov

Indeed, the key aspect here is the return type of the ternary expression, which is determined by the possible types of the operands. In this case, even though the boolean expression involves doubles, the ternary operator considers the common type compatible with both branches, which is float because float can accommodate both 12_456 and 12456.02f. This is why the result is float and not double.

iSnoverOption: D

The answer is the letter D, analyzing the expression, it returns a false, so it returns 124_56.02f (remembering that the _ does not separate the decimal place, it only separates the number, it only serves to help reading) so when adding 12456.02 + 1024 = 13480.02

alain001Option: D

float var1 = (12_345.01 >= 123_45.00) ? 12_456 : 124_56.02f; float var2 = var1 + 1024; System.out.println(var2);

babobobinaOption: C

Correct answer : C - 13480.0 float var1; if(12_345.01 >= 123_45.00){ var1 = 12_456; }else{ var1=124_56.02f } => the condition is true : 12345.01 > 12345.00 => var1 = 12_456 which means 12456 (The underscore is useful just for the readability). Then var 2 = var1 + 1024; => var 2 = 13480 => Output: 13480.0.

kob4yashiOption: D

tested. correct id D. but still can't say why