Results 1 to 3 of 3
  1. #1
    mhamill2 is offline Member
    Join Date
    Jun 2015
    Posts
    16
    Rep Power
    0

    Default Insert a line break with System.out.p

    Hi,

    I want to know if there is a way to insert a line break using System.out.print. For example, I want my code to output;

    Hello,
    How are you?

    Rather than;

    Hello, How are you?

    Is there a way to do this without using System.out.println on two different lines? Someone has mentioned using /n, but I'm not sure how that works.

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: Insert a line break with System.out.p

    You can embed a newline character (\n on Windows and Unix OS's and perhaps others) within a String. To be OS independent, it is probably best to use the line.separator property value. Regards, Jim
    Last edited by jim829; 06-02-2015 at 04:26 AM.
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: Insert a line break with System.out.p

    Quote Originally Posted by mhamill2 View Post
    Someone has mentioned using /n, but I'm not sure how that works.
    It doesn't work, it's '\n'. The other slash.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. Break Line BlueJ
    By cadujava860 in forum New To Java
    Replies: 1
    Last Post: 10-31-2011, 12:11 AM
  2. Replies: 0
    Last Post: 06-27-2011, 11:41 AM
  3. Need help calculating new line break width
    By ozzyman in forum New To Java
    Replies: 3
    Last Post: 05-04-2011, 01:54 PM
  4. Line break for textlayout
    By Java Tip in forum java.awt
    Replies: 0
    Last Post: 06-25-2008, 10:32 AM
  5. Line break in tool tip..how??
    By sandor in forum AWT / Swing
    Replies: 1
    Last Post: 05-16-2007, 01:45 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •