1Z0-811 Primitives, Strings and Operators Practice Question
Given the code snippet: int x = 5; int y = 2; double result = x / y; What is the value of result?
⚠ Common exam trap
Oracle often tests the distinction between integer and floating-point division, trapping candidates who forget that dividing two ints in Java always produces an int result, not a double, even when assigned to a double variable.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
2.0
In Java, when both operands of the division operator are integers (int), integer division is performed, which truncates the fractional part. Here, x / y evaluates to 5 / 2 = 2 (integer division), and then the int value 2 is implicitly widened to double 2.0 when assigned to the double variable result.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
2.0
Why this is correct
Correct because integer division yields 2, then cast to double.
- ✗
Compilation fails
Why it's wrong here
Incorrect because the code compiles.
- ✗
2.5
Why it's wrong here
Incorrect because integer division truncates.
- ✗
2
Why it's wrong here
Incorrect because result is double, so it is 2.0 not 2.
Go deeper
Related to this question
About these practice questions
Courseiva writes every 1Z0-811 question from scratch — 481 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This 1Z0-811 practice question is part of Courseiva's free Oracle certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the 1Z0-811 exam.