What is the output of the following Java program no. 2?

  1. class Test
  2. {
  3.     public static void main (String args[])
  4.     {
  5.         System.out.println(10 * 20 + “Javatpoint”);
  6.         System.out.println(“Javatpoint” + 10 * 20);
  7.     }
  8. }

The output of the above code will be

200Javatpoint
Javatpoint200

Explanation

In the first case, The numbers 10 and 20 will be multiplied first and then the result 200 is treated as the string and concatenated with the string Javatpoint to produce the output 200Javatpoint.

In the second case, The numbers 10 and 20 will be multiplied first to be 200 because the precedence of the multiplication is higher than addition. The result 200 will be treated as the string and concatenated with the string Javatpointto produce the output as Javatpoint200.