How is rounding performed under integer division

The fractional part of the result is truncated. This is known as rounding toward zero.

In Java, rounding is performed towards zero under integer division. This means that the fractional part is simply truncated, and the result is the integer quotient without rounding up or down.

For example, consider the following division:

java
int result = 7 / 3;

The result of this division would be 2. The fractional part (0.333…) is truncated, and the result is the integer part of the division.

If you want to perform rounding in a specific way, you may need to use the Math.round method or other rounding techniques after the division. For example:

java
double result = Math.round((double) 7 / 3);

In this case, the result would be 2.0 because the division is first performed as a floating-point division, and then Math.round is used to round the result to the nearest integer.