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 2 of 2

Thread: New to JAVA need some help with println multiple variables, I want to add a space

  1. #1
    Junior Member
    Join Date
    Sep 2011
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default New to JAVA need some help with println multiple variables, I want to add a space

    (Answered) Hello My name is harry nash (lostbit)
    I am new to JAVA. I want to know how to insert space between
    the value of two variables in the println statement. The code below
    outputs GoodbyeMood10 and I want GoodbyeMoon 10


    String var1 = "GoodbyeMoon";
    int var2 = 10;
    System.out.println(var1 + var2);

    The fix System.out.println(var1 + "s "+var2);
    Last edited by lostbit; September 24th, 2011 at 03:23 PM.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: New to JAVA need some help with println multiple variables, I want to add a spac

    If you want to concatenate Strings use the + operator between the Strings.
    For a single space, the String to use is two "s with a single space between them: " "

Similar Threads

  1. java.lang.OutOfMemoryError: Java heap space
    By Nikhat in forum Exceptions
    Replies: 7
    Last Post: April 21st, 2011, 07:31 AM
  2. Multiple Identical Scripts - Variables and Load Handlers
    By cas22 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 22nd, 2011, 11:37 AM
  3. Java Heap Space
    By aussiemcgr in forum Java Theory & Questions
    Replies: 4
    Last Post: September 8th, 2010, 05:05 PM
  4. AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space
    By nasi in forum What's Wrong With My Code?
    Replies: 6
    Last Post: March 25th, 2010, 10:37 PM
  5. Out of memory - Java heap space
    By fraxx in forum Java Theory & Questions
    Replies: 4
    Last Post: November 24th, 2009, 05:26 AM