~/ learn/ java-from-zero/ cards/ Gotcha roundup I — values & flow
1 of 4

Type a line showing integer division assigned to double

Type a line showing integer division assigned to double

Answer

double d = 7 / 2; // 3.0, not 3.5

Both operands are int so integer division runs first, yielding 3. That int is then widened to double 3.0. The variable type does not affect how the operands are evaluated.

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/bf4a596f-f0da-4a21-bcba-f2e1f61f1721/flashcard utf-8 LF