1/2 + 1/2 = 0
It looks as though this is a mistake, but no: each 1/2 calls for integer division, resulting in an integer 0. The two zeros are added to get the final answer, zero.
If you really want to add one half to one half you should write 1.0/2.0 + 1.0/2.0 because now the decimal points make each number a double. Here is a Java application that illustrates these points:
class integerDivision { public static void main ( String[] args ) { System.out.println("The result is: " + (1/2 + 1/2) ); } }
Remember that you can run this program by copying it to Notepad, saving to a file integerDivision.java, compiling and running it. See a previous chapter for details on doing this. It would be nice if you made a few changes to the program in Notepad then ran the program again the see the effect.
Notice the parentheses around (1/2 + 1/2)