Try to figure out the output of this code:
The reason behind this is – Initially the integers are added and we get the L.H.S. as 50. But, as soon as a string is encountered it is appended and we get “50=” . Now the integers after ‘=’ are also considered as a string and so are appended.
- To make the output 50=50, we need to add a bracket around the sum statement to overload the concatenation operation.
- This will enforce the sum
to happen before string concatenation as bracket as the highest precedence.
This article is contributed by Himanshi Gupta. If you like GeeksforGeeks and would like to contribute, you can also write an article and mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Program to Convert Set of Integer to Array of Integer in Java
- Integer.MAX_VALUE and Integer.MIN_VALUE in Java with Examples
- Printing Triangle Pattern in Java
- Programs for printing pyramid patterns in Java
- Java.lang.Integer class in Java
- Integer sum() Method in Java
- Integer toString() in Java
- How to calculate log base 2 of an Integer in Java?
- String to Integer in Java - parseInt()
- Java Integer compareTo() method
- Integer toOctalString() Method in Java
- Integer valueOf() Method in Java
- Integer floatValue() Method in Java
- How to pass integer by reference in Java
- Difference between an Integer and int in Java with Examples
- Java Integer compareUnsigned() method
- Java Integer bitCount() method
- Java Integer byteValue() method
- Java Integer compare() method
- Convert Double to Integer in Java