0

What is happening inside the System.out.println("1"+a);

int a=1; If 1 is a char then output is 50 but if 1 is a string output is 11 .can you clarify with what is happening if 1 is a string ?

8th Jul 2021, 4:11 PM
pavan
6 Answers
+ 2
Hello pavan Normally + means you add some numbers, right? But in case of Strings it concatenate them. "solo" + "learn" = "sololearn" "1" + "1" = "11"
8th Jul 2021, 5:30 PM
Denise Roßberg
Denise Roßberg - avatar
+ 2
Tq Denise once again
8th Jul 2021, 5:57 PM
pavan
+ 1
pavan "1" is not an integer. It is a String. int i = 1; an integer String s = "1"; a String
8th Jul 2021, 5:44 PM
Denise Roßberg
Denise Roßberg - avatar
+ 1
In case of a is an integer, println() converts it to a String because "1" is a String. I guess Java wanted to avoid an error message (normally you can't add a string with an integer). int a = 3; System.out.println("1" + 3); Output: "13"
8th Jul 2021, 5:55 PM
Denise Roßberg
Denise Roßberg - avatar
0
Tq Denise Are you telling that integer is directly converted into string wihout ASCII values?
8th Jul 2021, 5:33 PM
pavan
0
In parantheses( "1" +a) where a is interger right
8th Jul 2021, 5:47 PM
pavan