Explain what happens when a Java program attempts to divide one integer by another. What happens to the fractional part of the calculation? How can you avoid that outcome?

What will be an ideal response?

: Dividing two integers results in integer division—any fractional part of the calculation is lost (i.e., truncated). For example, 7 ÷ 4, which yields 1.75 in conventional arithmetic, truncates to 1 in integer arithmetic, rather than rounding to 2. To obtain a floating-point result from dividing integer values, a programmer must temporarily treat these values as floating-point numbers in the calculation by using the unary cast operator (double). As long as the (double) cast operator is applied to any variable in the calculation, the calculation will yield a double result which can be assigned to a double variable.

Computer Science & Information Technology

You might also like to view...

Water-cooled computers typically use no fans and are quieter, but can be very expensive

Indicate whether the statement is true or false

Computer Science & Information Technology

A(n) ________ is the page format the presentation will be presented on

A) template B) theme C) layout D) output medium

Computer Science & Information Technology