How come it gives 13 instead of 4=4 can someone explain pls | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 5

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

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

14th Apr 2021, 4:12 PM
Sharanāšœļø
Sharanāšœļø - avatar
5 Respostas
+ 4
The numbers written after string literal are regarded as string. So here Strings are concatenated
14th Apr 2021, 4:18 PM
Atul [Inactive]
+ 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)
14th Apr 2021, 5:38 PM
AĶ¢J
AĶ¢J - avatar
+ 2
To get 4=4 System.out.println((1+3)+"="+(1+3));
14th Apr 2021, 4:21 PM
Avinesh
Avinesh - avatar
+ 1
Oh ok got it buddy thnksšŸ‘šŸ»
14th Apr 2021, 4:20 PM
Sharanāšœļø
Sharanāšœļø - avatar
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.
14th Apr 2021, 4:23 PM
The future is now thanks to science
The future is now thanks to science - avatar