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

Thread: Noob Question: How to add spaces between each print

  1. #1
    Junior Member
    Join Date
    Sep 2013
    Posts
    18
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Noob Question: How to add spaces between each print

    So this is currently my code, I want it to add 3 spaces between each number printed.


    import java.util.Scanner;
     
    public class Addition
    {
        public static void main( String[] args )
        {
            Scanner input = new Scanner( System.in );
     
            int number1;
            int number2;
            int number3;
            int number4;
            int number5;    
     
            System.out.print( "Please enter your first integer: " );
            number1 = input.nextInt(); 
     
            System.out.print( "Please enter your second integer: " );
            number2 = input.nextInt(); 
     
            System.out.print( "Please enter your third integer: " );
            number3 = input.nextInt(); 
     
            System.out.print( "Please enter your fourth integer: " );
            number4 = input.nextInt(); 
     
            System.out.print( "Please enter your fifth integer: " );
            number5 = input.nextInt(); 
     
           System.out.print( number1 );
           System.out.print( number2 );
           System.out.print( number3 );
           System.out.print( number4 );
           System.out.print( number5 );
     
        }
    }


  2. #2
    Junior Member
    Join Date
    Sep 2013
    Posts
    3
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Noob Question: How to add spaces between each print

    You can use the escape sequence "\t" if you want.

    or you can combined them into one System.out and just add blank strings in between or "\t"

    System.out.print(number1 + "\t" + number2 + "\t"....number5

    or
    System.out.print(number1 + "  " + number2 + "  " + ....number5

  3. The Following User Says Thank You to radarmanman For This Useful Post:

    Knighter (September 28th, 2013)

  4. #3
    Junior Member
    Join Date
    Sep 2013
    Posts
    18
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Noob Question: How to add spaces between each print

    Okay thanks let me try this!

    --- Update ---

    Furthermore on that question (still learning a bit here, new to this code) what if they only had the option to type in one series of numbers, and i wanted it to separate each number with 3 spaces?

    import java.util.Scanner;

    public class Addition
    {
    public static void main( String[] args )
    {
    Scanner input = new Scanner( System.in );

    int number1;

    System.out.print( "Please enter your first integer: " );
    number1 = input.nextInt();



    System.out.print( number1 + " " );



    }
    }

  5. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Noob Question: How to add spaces between each print

    Try it and see what happens.

Similar Threads

  1. very noob question
    By javapol in forum What's Wrong With My Code?
    Replies: 3
    Last Post: March 6th, 2013, 03:24 AM
  2. Noob Question
    By javapol in forum What's Wrong With My Code?
    Replies: 3
    Last Post: January 23rd, 2013, 08:24 AM
  3. Most noob question ever.
    By SkyAphid in forum Java Theory & Questions
    Replies: 1
    Last Post: December 8th, 2011, 08:14 AM
  4. Total NOOB question
    By coolidge in forum Java Theory & Questions
    Replies: 3
    Last Post: September 2nd, 2011, 04:09 PM
  5. Noob question: Why .class?
    By Shaybay92 in forum Java Theory & Questions
    Replies: 10
    Last Post: August 22nd, 2011, 04:56 AM