Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Distinguish additive + and "connecting +" in system.out.println

  1. #1
    Junior Member
    Join Date
    Aug 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Distinguish additive + and "connecting +" in system.out.println

    As far as I know you have to use the + sign in your system.out.println command, if you want to connect several messages.
    Example: System.out.println("The house" + "green") ;
    However, do you make the compiler distinguish between the "connecting" + sign and the additive + sign? Especially if you want to use both together.
    For example: System.out.println("The current value of a+c is" + a+c) ;
    I am using the latest Eclipse version.

    I also noticed that you cannot simply use someting like System.out.println("blub" + c-a ) ;
    How can this be fixed ?


  2. #2
    Forum VIP
    Join Date
    Jun 2011
    Posts
    313
    My Mood
    Bored
    Thanks
    46
    Thanked 87 Times in 73 Posts
    Blog Entries
    4

    Default Re: Distinguish additive + and "connecting +" in system.out.println

    The String documentation explains how the + operator applies to Strings:

    The Java language provides special support for the string concatenation operator ( + ), and for conversion of other objects to strings. String concatenation is implemented through the StringBuilder(or StringBuffer) class and its append method. String conversions are implemented through the method toString, defined by Object and inherited by all classes in Java. For additional information on string concatenation and conversion, see Gosling, Joy, and Steele, The Java Language Specification.
    Computers are fascinating machines, but they're mostly a reflection of the people using them.
    -- Jeff Atwood

  3. #3
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,124
    My Mood
    Mellow
    Thanks
    186
    Thanked 658 Times in 645 Posts

    Default Re: Distinguish additive + and "connecting +" in system.out.println

    Welcome to the forum! Please read this topic to learn how to post code in code or highlight tags and other useful info for new members.

    If c - a is an arithmetic expression that should be evaluated before printing, then put it in parens.

Similar Threads

  1. System.out.println("Java lover presents himself");
    By derryper in forum Member Introductions
    Replies: 1
    Last Post: January 17th, 2014, 01:52 PM
  2. System.out.println("Hello Guys!");
    By Java Cub in forum Member Introductions
    Replies: 2
    Last Post: November 17th, 2013, 08:37 PM
  3. system.out.println("hello world")
    By pomy in forum Member Introductions
    Replies: 0
    Last Post: December 12th, 2012, 03:31 PM
  4. use of System.out.println(""); error....
    By rohan22 in forum Java Theory & Questions
    Replies: 2
    Last Post: July 16th, 2011, 10:49 AM
  5. System.out.println ("Hellow");
    By OnionzRingz in forum Member Introductions
    Replies: 1
    Last Post: March 1st, 2011, 04:56 PM