Results 1 to 11 of 11
- 01-24-2010, 06:22 AM #1
Member
- Join Date
- Jan 2010
- Posts
- 9
- Rep Power
- 0
can some one help me with nested loop?
Hi. I'm a beginner of java and im getting confusing about how to make an output like this.
JAVA
I want to make an output with this word by using nested loop.
I'm beginner but when I asked my friend how to do it, he just tole me to use the nested loop. but I dont know how the nested loop works. can any one help me with the code for this with nested loop or other easier way to do it?Last edited by keycoffee; 01-24-2010 at 06:28 AM.
-
The question you ask doesn't make much sense. What is the exact assignment that you have? Can you type it here word for word?
- 01-24-2010, 07:02 AM #3
Member
- Join Date
- Jan 2010
- Posts
- 46
- Rep Power
- 0
edit: nevermind..
Last edited by Newbie666; 01-24-2010 at 07:10 AM.
- 01-24-2010, 08:56 AM #4
Senior Member
- Join Date
- Oct 2009
- Location
- California,US
- Posts
- 201
- Rep Power
- 11
- 01-24-2010, 09:22 AM #5
Member
- Join Date
- Jan 2010
- Posts
- 12
- Rep Power
- 0
What RaIdEn said is correct, but if you want you can also use:
Java Code:import javax.swing.*; import java.awt.event.*; public class TestCode { public static void main (String[] args) { JOptionPane.showMessageDialog(null, "JAVA"); } }
- 01-24-2010, 05:01 PM #6
Member
- Join Date
- Jan 2010
- Posts
- 9
- Rep Power
- 0
thanks guys
I'm sorry guys. I misunderstood. I'm supposed to make the output like this.
*
**
***
****
I want to make this kind of output by using the word "JAVA" .
The question actually said like this
Write a program to display your first name on the screen by drawing the individual
letters using the same letters on a 5 × 5 grid.
This was the question what I was assigned to do. But it's my first week of my assignment and I didnt learn nothing much. I guess it's not the nested loop or the loop but just the simple code. But I really don't get how to do it cause I'm a really beginner. can some one teach me please? I appreciate it.
-
Given the confines of this forum and our other time commitments (we're volunteers after all), we're not so good at "teaching" here, but much better at answering direct questions such as, "I'm getting such-and-such error on line 34 with so-and-so code that I've posted below". To learn what you need to know requires study. I recommend that you start with your notes, your books, and this decent tutorial: reallybigindex
Much luck!
- 01-24-2010, 05:16 PM #8
Member
- Join Date
- Jan 2010
- Posts
- 9
- Rep Power
- 0
Thank you for the tips fubarable. I try to learn from the website which you posted. I appreciate it.
- 01-24-2010, 08:33 PM #9
Member
- Join Date
- Feb 2009
- Posts
- 92
- Rep Power
- 0
I am a bit lost as to the intent of your question.
Think you are asking for something like
Java Code:J JA JAV ....
You will have string fuctions something like substring ("JAVA", 0, 1) -> JA
Java Code:set string start index = 0 set string start index = 0 set string length while(loop index < stringLength) { print substring ("string", start_index, end _ndex); increment end_index }
I don't see the need for a nested loop.Last edited by rdtindsm; 01-24-2010 at 08:35 PM.
- 01-24-2010, 11:32 PM #10
This is a classic problem, though I usually see it with the **** like you demonstrated.
A nested loop simply means a loop inside a loop. It gives you two counting variables (in the case of a for loop which this problem usually uses).
So, you need to print out 4 lines and each line needs to print something an increasing number of times. See a pattern? line 1 prints 1 *. Line 2 prints 2 * and so on.
So, for every line you print, you need to print the same number of *'s as the line number.
That statement describes a nested loop - an outer loop that prints from 1 to n lines, and an inner loop that prints 1 to n *'s on that line. A combination of System.out.print("*"); and System.out.println(); inside a pair of loops will do the trick, try it out, I don't want to spoon feed it to you.
- 01-25-2010, 03:49 AM #11
Member
- Join Date
- Jan 2010
- Posts
- 9
- Rep Power
- 0
Similar Threads
-
Explanation of Nested Loop (very strange)
By Jonotron in forum New To JavaReplies: 5Last Post: 01-09-2011, 03:54 AM -
JAVA: String char removal with nested loop
By igniteflow in forum New To JavaReplies: 3Last Post: 11-28-2008, 03:09 AM -
I want to recreate the method drawRect with a nested for-loop
By chelseacortez in forum Java 2DReplies: 4Last Post: 09-05-2008, 05:47 PM -
nested for loop question
By javabob in forum New To JavaReplies: 3Last Post: 05-21-2008, 12:00 AM -
Nested For Loop
By yuchuang in forum New To JavaReplies: 1Last Post: 07-08-2007, 02:11 PM
Bookmarks