How come it gives 13 instead of 4=4 can someone explain pls | Sololearn: Learn to code for FREE!

+5

How come it gives 13 instead of 4=4 can someone explain pls

https://code.sololearn.com/ckixSQiC46LQ/?ref=app

4/14/2021 4:12:16 PM

Sharan⚜️

5 Answers

New Answer

+4

The numbers written after string literal are regarded as string. So here Strings are concatenated

+4

Sharan⚜️ After String if you add any number then it will just concat with string. So if you want 4=4 then just add brackets ( ) before and after the number like 1 + 3 + "=" + (1 + 3)

+2

To get 4=4 System.out.println((1+3)+"="+(1+3));

+1

Oh ok got it buddy thnks👍🏻

0

From my analysis, System.out.println(1+3+"="+1+3); First it starts from beginning, here it found 1+3 and both are integer so it adds them and 1+3=4.Then the next value is a string.So it adds 4+"=" which is "4=" The next number is 1 which is an integer and it adds with the string "4=" and becomes "4=1" .Now "4=1" is a string and the next value 3 is an integer.So it adds with "4=1" to int 3 and becomes "4=13". This is just my prediction .I am not sure with my theory.