Courseiva
Primitives, Strings and OperatorsmediumMultiple ChoiceObjective-mapped

1Z0-811 Primitives, Strings and Operators Practice Question

What is the result of the following code snippet? int a = 5; int b = 2; double c = (double) (a / b); System.out.println(c);

⚠ Common exam trap

The trap here is that candidates often believe the cast to double will cause the division to be performed in floating-point, but the cast is applied after the integer division, so the fractional part is already lost.

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

The expression `(a / b)` performs integer division, resulting in 2 (since both a and b are ints). The cast `(double)` is applied to the result of that integer division, converting the integer 2 to 2.0. The output is therefore 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.

  • 2

    Why it's wrong here

    c is double, so printed as 2.0.

  • 2.0

    Why this is correct

    a/b is integer division (2), then cast to double.

  • Compilation error

    Why it's wrong here

    Code compiles and runs.

  • 2.5

    Why it's wrong here

    To get 2.5, cast before division: (double)a/b.

About these practice questions

One of 481 original 1Z0-811 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

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.