1Z0-811 Primitives, Strings and Operators Practice Question
What is the result of the following code snippet? int x = 5; int y = 2; double z = x / y; System.out.println(z);
⚠ Common exam trap
The trap here is that candidates often forget Java performs integer division when both operands are integers, mistakenly assuming the result will be a floating-point value like 2.5 just because the variable is declared as double.
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), the operation performs integer division, which truncates the fractional part. Here, x / y = 5 / 2 = 2 (integer division), and then the result is implicitly widened to double when assigned to z, producing 2.0.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
3.0
Why it's wrong here
Incorrect: 5/2 is 2, not 3.
- ✗
2
Why it's wrong here
Incorrect: although the integer division yields 2, the variable z is of type double, so output is 2.0, not 2.
- ✓
2.0
Why this is correct
Correct: integer division yields 2, then assigned to double becomes 2.0.
- ✗
2.5
Why it's wrong here
Incorrect: integer division does not use floating-point arithmetic; 5/2=2, not 2.5.
Go deeper
Related to this question
About these practice questions
This 1Z0-811 question is part of Courseiva's 481-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam 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.