Java OCA OCP Practice Question 2543

Question

Consider the following program and predict the output:

public class Main {
     public static void main(String []args) {
             String s = new String("5");
             System.out.println(1.0+10.5+s+(1.0+10.5));
     }
}
  • a) 11.5511.5
  • b) 11.551.010.5
  • c) 1.010.551.010.5
  • d) 11.55(1.010.5)
  • e) 11.55(11.5)


a)

Note

The rule specified in the earlier explanation applies here also.

However, here, the order of computation is changed using brackets.

Hence, the + operator adds the numbers in the brackets first, and you get 11.5511.5.




PreviousNext

Related