+ 2

How does this code works String res=""+2+(4%2)+(5%2)+7; System.out.print(res); Output: 2017?

30th May 2018, 4:12 PM
Prathamesh Sawant
Prathamesh Sawant - avatar
4 Answers
+ 3
Ok thanx :)
30th May 2018, 4:52 PM
Prathamesh Sawant
Prathamesh Sawant - avatar
+ 2
But 2, 0, 1 and 7 are not strings so why don't it gives an error?
30th May 2018, 4:20 PM
Prathamesh Sawant
Prathamesh Sawant - avatar
+ 1
If I put String res = ""+hello; It gives an error saying hello is not recognised.
30th May 2018, 4:21 PM
Prathamesh Sawant
Prathamesh Sawant - avatar
+ 1
Was this("") intentionally made to convert other types into string by using concatenation or did someone just found it accidentally that concatenating any other data type with "" will convert it into string?
30th May 2018, 4:48 PM
Prathamesh Sawant
Prathamesh Sawant - avatar