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

Thread: how do you leave a line space in java?

  1. #1
    Junior Member
    Join Date
    Oct 2009
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy how do you leave a line space in java?

    Hi,

    I am trying to implement a controller function which will test all my methods.

    As a result of this class information will be displayed.

    Below is a sample of my coding.

    System.out.println("After copy method, is Date1 equal to Date2? ");
                if (Date2.equals(Date1))
                System.out.println("The copy method in class Date is functioning correctly. Date2 has been copied to Date1.");
     
                else
                {
                    System.out.println("The copy method in class Date is not functioning correctly");
     
                }

    I wish for there to be a blank line between "After copy method, is Date1 equal to Date2? " and whichever line is returned after the if statement. How do i implement this?

    Thanks in advance.


  2. #2
    Member
    Join Date
    Jul 2009
    Posts
    31
    Thanks
    3
    Thanked 6 Times in 5 Posts

    Default Re: how do you leave a line space in java?

    Characters (The Java™ Tutorials > Learning the Java Language > Numbers and Strings)
    System.out.println("After copy method, is Date1 equal to Date2? [B]\n[/B]");
                if (Date2.equals(Date1))
                System.out.println("The copy method in class Date is functioning correctly. Date2 has been copied to Date1.");
     
                else
                {
                    System.out.println("The copy method in class Date is not functioning correctly");
     
                }

    alternate 'solution'

    System.out.println("After copy method, is Date1 equal to Date2? ");
    [B]System.out.println();[/B]
                if (Date2.equals(Date1))
                System.out.println("The copy method in class Date is functioning correctly. Date2 has been copied to Date1.");
     
                else
                {
                    System.out.println("The copy method in class Date is not functioning correctly");
     
                }
    Last edited by rsala004; November 3rd, 2009 at 03:58 PM.

  3. #3
    Junior Member
    Join Date
    Oct 2009
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: how do you leave a line space in java?

    Entering \n literally prints that. Inserting \n after the quatation marks creates an error, illegal character:\92

    I have previously use the second method describe, System.out.println, however, it is not possible for this to be used within the if-else statement. Again this creates an error.

  4. #4
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: how do you leave a line space in java?

    ... \n is an escape character, and should be in between the quotations. Post your code so we can see what is going wrong?

  5. #5
    Member
    Join Date
    Jul 2009
    Posts
    31
    Thanks
    3
    Thanked 6 Times in 5 Posts

    Default Re: how do you leave a line space in java?

    you may have entered wrong slash, and typed it correctly here

  6. #6
    Junior Member
    Join Date
    Nov 2009
    Posts
    11
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: how do you leave a line space in java?

    \n which means next line

  7. #7
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Location
    Wales, Bangor & England, Warwickshire
    Posts
    820
    My Mood
    Cynical
    Thanks
    7
    Thanked 104 Times in 90 Posts

    Default Re: how do you leave a line space in java?

    \n means bad. Do not use it! It is not portable and doesn't work with file streams and things properly. You should use either a blank println statement or better yet.
    System.out.print(System.getProperty("line.separator"));

    Boo hisss at \n this is java! Do thigs properly.

    Chris
    chris[at]javaprogrammingforums[dot]com

    Prifysgol Bangor University, North Wales

  8. #8
    Junior Member
    Join Date
    Nov 2009
    Posts
    6
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: how do you leave a line space in java?

    i'm no expert, but woulden't this code just put a println after the println question? thus seporating the final println from the first? =
    System.out.println("After copy method, is Date1 equal to Date2? ");
    System.out.println("");
                if (Date2.equals(Date1))
                System.out.println("The copy method in class Date is functioning correctly. Date2 has been copied to Date1.");
     
                else
                {
                    System.out.println("The copy method in class Date is not functioning correctly");
     
                }
    Last edited by helloworld922; November 5th, 2009 at 09:05 PM.

Similar Threads

  1. Replies: 15
    Last Post: February 28th, 2010, 10:30 PM
  2. The input line is too long
    By vivekmk in forum Java IDEs
    Replies: 5
    Last Post: October 16th, 2009, 11:35 PM
  3. on-line shopping
    By sriraj.kundan in forum Web Frameworks
    Replies: 13
    Last Post: August 1st, 2009, 03:03 PM
  4. Reading a file line by line using the Scanner class
    By JavaPF in forum File Input/Output Tutorials
    Replies: 0
    Last Post: April 17th, 2009, 08:34 AM
  5. 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, 07:32 AM