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: Line Spacing

  1. #1
    Junior Member
    Join Date
    Sep 2014
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Line Spacing

    Hello Everyone,

    I am having a problem understanding line spacing. I need to write a program that has nested FOR LOOPS to produce the following output:
    1
    2
    3
    4
    5
    I can get a for loop that counts down. The problem I have is using for loop for line spacing.
    Can anyone show me an example of this or explain to me in an easy way how a for loop for a line works.

    Thanks


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

    Default Re: Line Spacing

    Show what you've tried posted properly in code tags, and we can go from there. We also need to see what the output should look like, so put that in code tags too. Code tags will preserve the spacing you need to show us.

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,401
    Thanks
    53
    Thanked 2,399 Times in 2,352 Posts

    Default Re: Line Spacing

    Is the output shown in the post the way you want it to look? Or are there leading spaces that the forum's software has removed? If there are missing spacing, wrap the output in code tags to preserve the spacing.

    To wrap your output with code tags:
    [code=java]
    THE OUTPUT GOES HERE
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  4. #4
    Member
    Join Date
    Apr 2014
    Posts
    219
    Thanks
    8
    Thanked 2 Times in 2 Posts

    Default Re: Line Spacing

    Create a loop
    System.out.print(); will not make a new line, unless you add \n of course.
    System.out.println(); Will create a new line.

    Then simply right out your loop.

    There are lots of examples on google showing this. You should have no problem finding this.

Similar Threads

  1. Re: Reading a file line by line using the Scanner class
    By javainbrain in forum File I/O & Other I/O Streams
    Replies: 8
    Last Post: September 16th, 2014, 08:10 AM
  2. Replies: 10
    Last Post: September 16th, 2011, 07:49 PM
  3. Help with formatting spacing on a calender grid please!
    By bulx0001 in forum What's Wrong With My Code?
    Replies: 9
    Last Post: June 27th, 2011, 12:53 AM
  4. How to Read a file line by line using BufferedReader?
    By JavaPF in forum File Input/Output Tutorials
    Replies: 0
    Last Post: May 19th, 2008, 06:32 AM
  5. How to Read a file line by line using BufferedReader?
    By JavaPF in forum Java Code Snippets and Tutorials
    Replies: 0
    Last Post: May 19th, 2008, 06:32 AM