string in java and python | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

string in java and python

public class Program { public static void main(String[] args) { System.out.println( 1 + '2' + 3 + '4'); } } OUTPUT 106

5th Apr 2018, 7:09 PM
Smriti Rastogi
Smriti Rastogi - avatar
3 Answers
+ 1
@Smriti Rastogi, I guess they are, probably, I'm no good with Java : ) anyways, it seems that when a number meets a double quoted string the number would be casted into string, and + sign concatenated the number (that had been casted as string) with double quoted string. When a number meets single quoted string (char) the char will be treated as a number (based on its ASCII code) and + sign add the number with the ASCII number of the respective char. I hope my explanation here makes sense : ) Hth, cmiiw
6th Apr 2018, 6:33 AM
Ipang
+ 6
The '2' is interpreted by its ASCII value (50), and so is also '4', which is counted for as 52, so it actually sum 1 + 50 + 3 + 52 = 106
5th Apr 2018, 7:14 PM
Ipang
+ 1
single quoted string and doubly quoted list are treated differently....??
5th Apr 2018, 9:50 PM
Smriti Rastogi
Smriti Rastogi - avatar