Originally posted by sona nagee:
concatinating the strings with any other primitive type converts them to string
System.out.println(" " + 2 + 3)
output
23
System.out.println(2 + 3 +"")
output
5
can someone explain why?
Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
Originally posted by Stevie Kaligis:
[B]System.out.println('2'+3+"");
will be evaluate : (('2'+3)+"")
1. ('2'+3) convert to integer,
2. ((50 + 3) + "")
output : 53
System.out.println( '2'+'3'+"");
will be evaluate : (('2'+'3')+"")
1. ('2'+'3') convert to integer,
2. ((50 + 51) + "")
output : 101
Stevie:
Could you please explain how '2' in char evaluates to 50 in int?
Thanks.
Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
Originally posted by Jane Griscti:
Hi Parimala,
'char' types are represented internally by their Unicode values. The Unicode value of '2' is 50, the Unicode value of '3' is 51. That's why you can perform arithmetic operations on them.
Hope that helps.
Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
Consider Paul's rocket mass heater. |