What does this statement print? System.out.println(5 + "bc");

3 answers

uh, did you ever think of actually executing it?
It will print "5bc"
because + works both as arithmetic as well as concatenation operator. And all the expressions are executed from left to right. So in case of 2 + 3 + "bc" it first adds 2 and 3 acting as arithmetic operator and then when it finds string on one side and number on other at that time it acts as concatenation operator. So,
print(2+3+"bc") prints 5bc
print("bc"+2+3) prints bc23
It's always a good idea to read the language documentation ...
because + works both as arithmetic as well as concatenation operator. And all the expressions are executed from left to right. So in case of 2 + 3 + "bc" it first adds 2 and 3 acting as arithmetic operator and then when it finds string on one side and number on other at that time it acts as concatenation operator. So,
print(2+3+"bc") prints 5bc
print("bc"+2+3) prints bc23
print(2+3+"bc") prints 5bc
Similar Questions
  1. What does this statement print?System.out.println("bc" + 2 + 3)
    1. answers icon 5 answers
    1. answers icon 1 answer
  2. What does this statement print?System.out.println(“bc”+2+3)
    1. answers icon 1 answer
  3. Which of the following is / are valid code?a) System.out.println(Integer.add(2,2)); b) Float[] ar= new Float[] { new Float(1.0),
    1. answers icon 2 answers
more similar questions