Академический Документы
Профессиональный Документы
Культура Документы
Java FAQ
Recent Topics
Register / Login A friendly place for programming This week's giveaway is in the Jobs Discussion forum. greenhorns! We're giving away four copies of Presenting for Geeks
and have Dirk Haun on-line! See this thread for details.
Author
sout- concatenation
posted 4/5/2007 11:01 AM
Here goes the code: [code] class Feline{ public static void main(String[] args){ Long x = 42l; Long y = 44l; System.out.println(" " + 7 + 2 + ""); //line1 System.out.println(foo() + x + 5 + ""); //line2 System.out.println(x + y + foo()); //line3 } static String foo(){return "foo";} } [\code] My Doubt: Why in line 1 the output is 72? and why in line 3 the output is 86foo? I don't see any consistency.. Can somebody please explain? Thanks.
www.coderanch.com/t/262281/java-programmer-SCJP/certification/sout-concatenation
1/3
7/16/13
Chandra Bhatt Ranch Hand Joined: Feb 28, 2007 Posts: 1707
Hi Guptajee,
view plain
c opy to c lipboard
N ote: T ext c ontent in the c ode bloc ks is automatic ally word- wrapped
0 1 . 0 2 . 0 3 . 0 4 . 0 5 . 0 6 . 0 7 . 0 8 . 0 9 . 1 0 .
My Doubt: Why in line 1 the output is 72? and why in line 3 the output is 86foo?
if any one of the left and right operand of the "+" concatenation operator is String, the resultant would be String concatenation. If both are number it would be addition. Remember left to right operation. Thanks and Regards, cmbhatt
cmbhatt
Thanks..Got it..!!
www.coderanch.com/t/262281/java-programmer-SCJP/certification/sout-concatenation
2/3
7/16/13
Similar Threads Doubt in String concatenation (KB Chapter 4) Concatination Operator doubt about string concatenation concatenation Assertion topic
All times above are in your local time zone & format.T he current ranch time (not your local time) is Jul 16, 2013 07:47:59 .
www.coderanch.com/t/262281/java-programmer-SCJP/certification/sout-concatenation
3/3