The Artima Developer Community
Sponsored Link

Java Answers Forum
Nested for loops

3 replies on 1 page. Most recent reply: Aug 7, 2002 3:07 AM by Matt Gerrans

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 3 replies on 1 page
Leo

Posts: 6
Nickname: dev313
Registered: Aug, 2002

Nested for loops Posted: Aug 6, 2002 9:39 PM
Reply to this message Reply
Advertisement
What is a good process to learn how to manipulate nested for loops. It's easy to get lost in the trace through.

What I want to do is make a graphic like this one using a nested for loop.

**********
*********
********
*******
******
*****
****
***
**
*

Also,

*
**
***
****
*****
******
*******
********
*********
**********

How is this done??

Many thanks to everyone?

Leo


Leo

Posts: 6
Nickname: dev313
Registered: Aug, 2002

Re: Nested for loops Posted: Aug 6, 2002 9:43 PM
Reply to this message Reply
These examples didn't come out the way I typed them in. The first example should look like this only with asterisks:

10 9 8 7 6 5 4 3 2 1
9 8 7 6 5 4 3 2 1
8 7 6 5 4 3 2 1
7 6 5 4 3 2 1
6 5 4 3 2 1
5 4 3 2 1
4 3 2 1
3 2 1
2 1
1

The second one should look like this:

1
2 1
3 2 1
4 3 2 1
5 4 3 2 1
6 5 4 3 2 1
7 6 5 4 3 2 1
8 7 6 5 4 3 2 1
9 8 7 6 5 4 3 2 1
10 9 8 7 6 5 4 3 2 1

Any ideas??

Leo

Posts: 6
Nickname: dev313
Registered: Aug, 2002

Re: Nested for loops Posted: Aug 6, 2002 9:45 PM
Reply to this message Reply
nothing is right aligning like it should.

Matt Gerrans

Posts: 1153
Nickname: matt
Registered: Feb, 2002

Re: Nested for loops Posted: Aug 7, 2002 3:07 AM
Reply to this message Reply
You could do either of those with a single for-loop, no nesting required.

If you want to practice nested loops, try implementing a simple sorting algorithm, like a selection sort on a List.

Flat View: This topic has 3 replies on 1 page
Topic: Effedct of changing system time on currently active applications Previous Topic   Next Topic Topic: could anyone help me to slove this problem??

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use