What is the output of the following application?
public class MyClass { public static void main(String[] in) { int tiger = 2; short lion = 3; long winner = lion+2*(tiger + lion); System.out.print(winner); } /*from ww w . ja v a 2s .c o m*/ ? }
B.
For this problem, it helps to recognize that parentheses take precedence over the operations outside the parentheses.
Once we replace the variables with values, the expression becomes: 3+2*(2+3).
We then calculate the value inside the parentheses to get 3+2*5.
Since the multiplication operator has higher precedence than addition, we evaluate it first, resulting in 3+10 = 13, making Option B the correct answer.