Duplicate Question
The question on this page has been marked as a duplicate question.
Original Question
What does this statement print? System.out.println("bc" + 2 + 3)Asked by salouh
What does this statement print? System.out.println(5 + "bc");
Answers
Answered by
oobleck
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 ...
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 ...
Answered by
Abdelrhman
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
print("bc"+2+3) prints bc23
Answered by
Parthiv Jitesh dessi
print(2+3+"bc") prints 5bc
There are no AI answers yet. The ability to request AI answers is coming soon!
Submit Your Answer
We prioritize human answers over AI answers.
If you are human, and you can answer this question, please submit your answer.