Results 1 to 11 of 11
Thread: How to insert blank lines
- 02-17-2011, 05:40 AM #1
Member
- Join Date
- Feb 2011
- Posts
- 20
- Rep Power
- 0
- 02-17-2011, 05:41 AM #2
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
try System.out.println();
- 02-17-2011, 05:43 AM #3
Member
- Join Date
- Feb 2011
- Posts
- 15
- Rep Power
- 0
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):
That would output the following:Java Code:System.out.println("hey"); System.out.println("dude");
"hey
dude
"
That would output:Java Code:System.out.print("hey "); System.out.print("dude ");
"hey dude ".
- 02-17-2011, 05:47 AM #4
Member
- Join Date
- Feb 2011
- Posts
- 20
- Rep Power
- 0
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(); }
- 02-17-2011, 05:50 AM #5
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
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.
- 02-17-2011, 05:52 AM #6
Member
- Join Date
- Feb 2011
- Posts
- 15
- Rep Power
- 0
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:
Make sure to have "int i" in main.Java Code:for (i = 0; i <= 20; i++) System.out.println();
- 02-17-2011, 05:55 AM #7
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
- 02-17-2011, 05:57 AM #8
Member
- Join Date
- Feb 2011
- Posts
- 20
- Rep Power
- 0
Thnaks :D
its working
- 02-17-2011, 05:59 AM #9
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
Glad you figured it out. Mark your thread solved by clicking thread tools at the top.
- 02-17-2011, 06:00 AM #10
Member
- Join Date
- Feb 2011
- Posts
- 15
- Rep Power
- 0
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.
- 02-17-2011, 06:10 AM #11
Similar Threads
-
how can we remove blank lines from a .txt
By Camden in forum New To JavaReplies: 12Last Post: 07-29-2011, 01:38 PM -
Blank screen
By dewitrydan in forum New To JavaReplies: 14Last Post: 08-12-2010, 05:19 PM -
Blank Applet on JCreator
By mgm2010 in forum New To JavaReplies: 0Last Post: 05-05-2009, 03:21 PM -
Blank space
By sandy1028 in forum New To JavaReplies: 1Last Post: 04-21-2009, 10:00 AM -
How to insert large data into database using one insert query
By sandeepsai39 in forum New To JavaReplies: 3Last Post: 02-28-2009, 09:17 AM


LinkBack URL
About LinkBacks
Reply With Quote
.gif)

Bookmarks