What will be the output of the following code snippet: System.out.println(10 + 20 + "Hello" + 30 + 40);?

  • 100200Hello3040
  • 1020Hello3040
  • 5070Hello
  • Hello10203040
In Java, when you use the + operator with both numbers and strings, it performs left-to-right addition. So, the numbers are added first, and then the result is concatenated with the strings. The correct output is "1020Hello3040."
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *