The first statement is "System.out.println (1/2 + 1/2 +" = 1/2 + 1/2 "); prints 0 because the integer value obtained from 1/2 is zero. The rest is discarded and since 1/2 is equal to 0.5, .5 is discarded. The second statement is "System.out.println (" 1/2 + 1/2 = "+ 1/2 + 1/2); prints 00 because of the concatenation sign. In the second expression, the first integer 1 is shown as +1, so the operator is actually read as (+1/2 +1/2), so it returns 00. If the second statement was configured as follows:
System.out.println("1/2+1/2="+ (1/2+1/2));
The result will be the same as the first statement.
Jnicholas76
source share