Which of the following code snippets will print exactly 10?
1. Object t = new Integer (106); int k = ((Integer) t).intValue ()/10; System.out.println (k); /*from w w w . j a v a2 s .c om*/ 2. System.out.println (100/9.9); 3. System.out.println (100/10.0); 4. System.out.println (100/10); 5. System.out.println (3 + 100/10*2-13);
Select 3 options
Correct Options are : A D E
For Code 1.
Since both the operands of / are ints, it is a integer division.
The resulting value is truncated and not rounded.
Therefore, the above statement will print 10 and not 11.
For Code 5.
precedence of / and * is same and is higher than + and -.