Results 1 to 4 of 4
Thread: Noob Question - printing loop
- 04-28-2012, 03:57 PM #1
Member
- Join Date
- Apr 2012
- Posts
- 9
- Rep Power
- 0
Noob Question - printing loop
Hi, I'm new to the forum and a completely new to java so please be too critical ^^!
What I'm trying to do is to print 3 blank lines, then 3 lines of 13 dots under it, followed by another 2 blank lines and finally a line of 13 underscores.
Since I'm a complete noob, this messy piece of code is what I've got so far. Would anyone be kind enough to help me simplify it please? Any help will be appreciated!
Java Code:for (int y = 1; y <= 3; y++) { for (int x = 0; x < 13; x++) { System.out.print(" "); } System.out.println(); } for (int y = 4; y <= 6; y++) { for (int x = 0; x < 13; x++) { System.out.print("."); } System.out.println(); } for (int y = 7; y <= 8; y++) { for (int x = 0; x < 13; x++) { System.out.print(" "); } System.out.println(); } for (int x = 0; x < 13; x++) { System.out.print("_"); System.out.println(); }
- 04-28-2012, 04:05 PM #2
Re: Noob Question - printing loop
1. Does a 'blank line' mean 13 space characters? I wouldn't interpret it that way/
2. Have you learned to use methods? I would make a method for printing 13 times (on the same line) the character passed to it as a parameter and call that method from inside a loop. That would move the inner loops to the new method and make the code cleaner.
3. Have you learned to use arrays? You could put the character for each line in an array and iterate over the array calling the method described above. That would reduce the main code to a single loop.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 04-28-2012, 04:13 PM #3
Member
- Join Date
- Apr 2012
- Posts
- 9
- Rep Power
- 0
Re: Noob Question - printing loop
Hello sir and thank you very much for your quick reply.
I will try to create the method you hinted me to. About the arrays, I have not learned much about arrays, would you mind to provide me with an example of how to approach this issue please? I will be very very appreciated :D
Or is there anyway to do it like this:
Assume x is the number of characters to be printed, and y is the number of lines. Create a loop so that on line 1-3 print blanks, line 4-6 print dots, line 7-8 print blanks and line 9 print underscores.Last edited by pantaloc; 04-28-2012 at 04:19 PM.
- 04-28-2012, 07:01 PM #4
Re: Noob Question - printing loop
Why do they call it rush hour when nothing moves? - Robin Williams
Similar Threads
-
noob question!
By swp in forum New To JavaReplies: 5Last Post: 09-28-2011, 11:14 PM -
noob question. plz help tho!
By swp in forum New To JavaReplies: 2Last Post: 09-28-2011, 06:16 AM -
Probably Really Noob Question
By bpx95 in forum New To JavaReplies: 2Last Post: 05-16-2011, 01:44 AM -
Noob button question.
By dudejonne in forum Java AppletsReplies: 4Last Post: 10-20-2009, 10:51 PM -
Question - I'm a noob!
By Insaeno in forum New To JavaReplies: 5Last Post: 08-04-2008, 03:20 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks