Course contentsShow
← Java
Lesson 87 of 2,8703. Operators and ExpressionsFree lesson

Integer Division and Truncation

Understand how dividing two integers produces an integer result, discarding the fractional part.

Integer Division and Truncation

You'll learn: How dividing two integers in Java produces an integer result by discarding any fractional part.

The Core Idea

When you divide one integer by another in Java, the result is always an integer—never a decimal. Java doesn't round to the nearest whole number; it truncates (chops off) everything after the decimal point.

Think of it like cutting a pizza: if you have 7 slices and 3 people, each person gets 2 slices (7 / 3 = 2). The remaining slice exists (that's the remainder, which you'll explore with %), but the division operation itself ignores it entirely.

How It Works in Practice

int result1 = 10 / 3;  // result1 is 3, not 3.333...
int result2 = 7 / 2;   // result2 is 3, not 3.5
int result3 = 5 / 10;  // result3 is 0, not 0.5

Notice that last example carefully: 5 / 10 equals 0 because the actual answer (0.5) gets truncated. The fractional part simply disappears.

Why This Happens

Java follows strict typing rules. When both operands are integers (int, long, short, or byte), Java assumes you want an integer result. The fractional component is not rounded—it's erased completely.

This behavior applies regardless of how you store the result:

int wholeNumber = 9 / 4;  // wholeNumber is 2

The division happens before assignment, so 9 / 4 becomes 2, then that 2 gets stored.

Key Takeaway: Dividing two integers in Java always produces an integer by truncating (not rounding) any fractional part—be especially careful with divisions that might produce values less than 1.