Let's understand by a program :
public static void main(String[] args) {
String S1 = " String1 ";
String S2 = " String2 ";
char c1 = 'a';
char c2 = 'b';
int i1 = 10;
int i2 = 20;
System.out.println(S1 + c1 + i1); // String1 a10
System.out.println(c1 + S1 + i1); // a String1 10
System.out.println(S1 + i1 + i2); // String1 1020
System.out.println(i1 + i2 + S1); // 30 String1
System.out.println(S1 + c1 + c2); // String1 ab
System.out.println(S1 + S2 + c1 + c2 + i1 + i2); // String1 String2 ab1020
System.out.println(i1 + c1 + i2); // 127
System.out.println(i1 + S1 + i2); // 10 String1 20
System.out.println(S1 + c1 + S2); // String1 a String2
System.out.println(S1 + i1 + S2); // String1 10 String2
System.out.println(S1 + i1 + i2 + S2); // String1 1020 String2
System.out.println(S1 + S2); // String1 String2
System.out.println(c1 + c2); // 195
System.out.println(S1 + c1); // String1 a
System.out.println(S1 + i1); // String1 10
System.out.println(i1 + c1); // 107
System.out.println(i1 + c1 + S1); // 107 String1
System.out.println(c1 + c2 + S1); // 195 String1
}
Excerpts :
1) If there is char and int combination then the ASCII value of char will be summed up with integer
2) If there is only integer , then it will be summed up.
3) If there is integer before String, then integer will be added up and will be concatenated with string.
4) If there is Integer after string , then string will be concatenated with int. No addition will happen.
5) Char or Int prior to string will be summed up but if it is after the string it will not be summed up
No comments:
Post a Comment