|
|
Java math fun!Sometimes math results are slightly different than expected when using Java. This often comes about because Java considers the type of number when doing math operations. The result of a math operation can only be placed in a variable that can contain the result. Remember that variables take up different amounts of memory based on their type. Bytes take up less space than integers take up less space than doubles etc.
It is possible to put an integer math result into a double variable (a bigger box) but trying to do the opposite will cause Java to complain. Look at this java file: DivisionTest.java Compile and running the DivisionTest.java file. You should see output
similar to this: You will note the following things:
|
| ||||