Before calculating, the number of operands will be transformed from low precision to high precision, and the accuracy of the original operand is Double, Float, Long, Int, short, char, byte, and transformed results, from high to Low for Double, Float, long, int, which is the specific number of highest precision in the original operand. This transformation is also called binary number, binary number promotion. When two operands are integrity, the results of addition, subtraction, and multiplication are integrated, but it may be very large and cannot be used by operands. Representation. Integer values cannot represent decimals.
The integer division in Java is rounded to 0. If the divisor is 0, AritHMeticeXception is generated (ie, "removal is" exception). The exception is too large when the result is too large, Java does not produce an exception, but abandon redundant bit. Such symbolic (at the highest bit) may be affected. So: If the number operated is close to a particular type of boundary, you should use a larger type of range, and check the results after calculating the results. The floating point calculation in Java will not produce an exception, which will generate three different values: is endless, endless and non-numbers. For details, refer to Appendix A. In Java, the floating point number can be modeled, but note that the book is wrong: "The value of the floating point operation X% Y is N, indicating that N is the maximum value of Y * n is less than equal to X", "in fact, floating point operation x% The value of Y is n, indicating that N is a maximum value that satisfies Y * Z N less than or equal to X (Z is integer, business). The following program verifies the mode of mode of floating point.
// Test.java class test {public static void main (String [] args) {system.out.println (16.5% 3);}}
2.10.1 Example of an integer operation: makechange.java
// MakeChange.java - change in dimes and penniesimport tio *; // use the package tio class MakeChange {public static void main (String [] args) {int price, change, dimes, pennies; System.out.println (. "TYPE PRICE (0 to 100):"); Price = console.in.readint (); Change = 100 - price; // how much change Dimes = Change / 10; // Number of Dimes Pennies = Change% 10; // Number of Pennies System.out.Print ("THE CHANGE IS:"); System.out.Println (DIMES "DIMES" Pennies "Pennies");}}
Earth people know.