Results 1 to 11 of 11
  1. #1
    durdanto is offline Member
    Join Date
    Feb 2011
    Posts
    20
    Rep Power
    0

    Default How to insert blank lines

    How do we insert blank line? For example, for a word game, I need to write a code that promt user to write a word and then once user enters the word and press enter, I need 20 blank lines there to clear the screen. I am new to java. Plz help.

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    try System.out.println();

  3. #3
    </3java is offline Member
    Join Date
    Feb 2011
    Posts
    15
    Rep Power
    0

    Default

    Do System.out.println(); if you want it to move down a line, System.out.print(); if you want it to continue on one line (look below for examples):

    Java Code:
    System.out.println("hey"); 
    System.out.println("dude");
    That would output the following:

    "hey
    dude

    "

    Java Code:
    System.out.print("hey "); 
    System.out.print("dude ");
    That would output:
    "hey dude ".

  4. #4
    durdanto is offline Member
    Join Date
    Feb 2011
    Posts
    20
    Rep Power
    0

    Default

    Do i need to write "System.out.println();" 20 times?

    So far this is what i have done:

    Java Code:
    {
    		//Welcome messages and instruction
    		System.out.println
    				(" ------------------------------------- \n" +
    				"\tWelcome to HANGMAN" +
    				"\n\t(Nancy's version)\n" +
    				" ------------------------------------- \n");
    		System.out.println ("OK Guessing Player ... " +
    				"turn around, while your friend enters the word to guess!");
    		System.out.println ("\nOther Player - " +
    				"Enter your word (letters only, " +
    				"no repeated letters and not case sensitive):" );
    		
    		Scanner kb = new Scanner(System.in);
    		String firstGuess = kb.next();
    		System.out.println(); 
    
    	}

  5. #5
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    You could type System.out.println() 20 times, but as Im guessing you are already thinking, it's a bit of a waste of time. You can simplify this with a loop which does the repetition for you.

  6. #6
    </3java is offline Member
    Join Date
    Feb 2011
    Posts
    15
    Rep Power
    0

    Default

    Instead of outputting it 20 times, why not write a for loop so you can change that 20 to any number you want, plus the code will be cleaner:

    Java Code:
    for (i = 0; i <= 20; i++)
    System.out.println();
    Make sure to have "int i" in main.

  7. #7
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    Quote Originally Posted by </3java View Post
    Instead of outputting it 20 times, why not write a for loop so you can change that 20 to any number you want, plus the code will be cleaner:

    Java Code:
    for (i = 0; i <= 20; i++)
    System.out.println();
    Make sure to have "int i" in main.
    For the op's information, and yours, you can also declare the i in the loop
    Java Code:
    for(int i = 0; i < 19; i++)

  8. #8
    durdanto is offline Member
    Join Date
    Feb 2011
    Posts
    20
    Rep Power
    0

    Default

    Thnaks :D
    its working

  9. #9
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    Glad you figured it out. Mark your thread solved by clicking thread tools at the top.

  10. #10
    </3java is offline Member
    Join Date
    Feb 2011
    Posts
    15
    Rep Power
    0

    Default

    Oh, alright. I am new as well so you learn something new everyday :)

    and yeah, I was wrong above. it should be i < 19 because 0 is included (0 to 19 = 20 integers). Its a good habit to start off loops and stuff now at 0, because things youll see later will be starting at 0.

  11. #11
    goldest's Avatar
    goldest is offline Senior Member
    Join Date
    Oct 2009
    Location
    Pune, India
    Posts
    469
    Rep Power
    5

    Wink

    Quote Originally Posted by </3java View Post
    it should be i < 19 because 0 is included (0 to 19 = 20 integers).
    It should be i <= 19 to make it 20 times starting from 0. Notice "<=" condition.

    Goldest
    Java Is A Funny Language... Really!
    Click on * and add to member reputation, if you find their advices/solutions effective.

Similar Threads

  1. how can we remove blank lines from a .txt
    By Camden in forum New To Java
    Replies: 12
    Last Post: 07-29-2011, 01:38 PM
  2. Blank screen
    By dewitrydan in forum New To Java
    Replies: 14
    Last Post: 08-12-2010, 05:19 PM
  3. Blank Applet on JCreator
    By mgm2010 in forum New To Java
    Replies: 0
    Last Post: 05-05-2009, 03:21 PM
  4. Blank space
    By sandy1028 in forum New To Java
    Replies: 1
    Last Post: 04-21-2009, 10:00 AM
  5. Replies: 3
    Last Post: 02-28-2009, 09:17 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
  •