Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / March 2008

Tip: Looking for answers? Try searching our database.

nested for loops

Thread view: 
nosmadadivad@gmail.com - 17 Feb 2008 01:08 GMT
Hi all, I'm new to java and google groups alike.  I needed some help
on creating the following out put.

1
22
333
4444
55555
666666
7777777
88888888
999999999

I've seen it done in class but can't seem to remember.  There were
only two for loops in the code.  Can someone help me with the code?
In the Middle of the Pack - 17 Feb 2008 01:39 GMT
> Hi all, I'm new to java and google groups alike.  I needed some help
> on creating the following out put.
[quoted text clipped - 11 lines]
> I've seen it done in class but can't seem to remember.  There were
> only two for loops in the code.  Can someone help me with the code?

For a homework assignment, help here will be very limited.
nosmadadivad@gmail.com - 17 Feb 2008 01:46 GMT
On Feb 16, 8:39 pm, In the Middle of the Pack <a...@nospamcentral.com>
wrote:
> nosmadadi...@gmail.com wrote:
> > Hi all, I'm new to java and google groups alike.  I needed some help
[quoted text clipped - 16 lines]
>
> - Show quoted text -

No, right I understand.  I understand homework shouldn't be done by
anyone but the student however this is not homework.. This new concept
was introduced yesterday Friday and I didn't have a good grasp on it.
I wanted to use this weekend to stare at the code and learn how it
works.  I've already finished all currently assigned programming
projects for the class.  This is more a desire to stay ahead and not
fall behind.  My brain doesn't quite understand this nested for loops
easily and felt it necessary to familiarize myself.
Roedy Green - 01 Mar 2008 19:07 GMT
> My brain doesn't quite understand this nested for loops
>easily and felt it necessary to familiarize myself.

Do you understand for loops?  If not read up on them. They are covered
in every introductory text, including free online ones.

Do you understand a for loop that calls a method?

Do you understand a method that calls a for loop?

If you understand yes to both questions you can nest?

Do you understand how to encapsulate/unravel a method?

If yes, then you can nest for loops. Just don't look at the whole
thing.  look at each loop as   for ( stuff ) { body };

Close your eyes for the moment than the body may be yet another for
loop.  It is a problem very much like factoring in algebra.  You have
to close your eyes to detail not currently relevant.
--

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
Jeff Higgins - 17 Feb 2008 01:46 GMT
nosmadadivad wrote:
> Hi all, I'm new to java and google groups alike.  I needed some help
> on creating the following out put.
[quoted text clipped - 11 lines]
> I've seen it done in class but can't seem to remember.  There were
> only two for loops in the code.  Can someone help me with the code?

For the code to be executable
there must have been more than two for loops.

public class Print {
 public static void main(String[] args) {
   for( ... ) {
     for( ... ) {
       System.out.print(); }
     System.out.println(); } } }
nosmadadivad@gmail.com - 17 Feb 2008 01:51 GMT
> nosmadadivad wrote:
> > Hi all, I'm new to java and google groups alike.  I needed some help
[quoted text clipped - 24 lines]
>
> - Show quoted text -

oh, well right.  You're right... clairification - I needed to know
what the code is within the
for (THIS CODE){
   for(THIS CODE){
.. anyways I googled it and the code came up.  Thanks for your
responses.  Off to study I go.....
Jeff Higgins - 17 Feb 2008 02:13 GMT
I needed to know
what the code is within the
for (THIS CODE){
   for(THIS CODE){
.. anyways I googled it and the code came up.  Thanks for your
responses.  Off to study I go.....
Yup,congrats,you're welcome,bye.
Roedy Green - 17 Feb 2008 09:59 GMT
>Hi all, I'm new to java and google groups alike.  I needed some help
>on creating the following out put

see http://mindprod.com/jgloss/homework.html
http://mindprod.com/jgloss/tackling.html

Here is a simpler problem for you to warm you up.

Draw this with a for loop

xxxxxxxxxxxxxx

See http://mindprod.com/jgloss/jcheat.html
--

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
nosmadadivad@gmail.com - 17 Feb 2008 18:47 GMT
On Feb 17, 4:59 am, Roedy Green <see_webs...@mindprod.com.invalid>
wrote:
> On Sat, 16 Feb 2008 17:08:38 -0800 (PST), nosmadadi...@gmail.com
> wrote, quoted or indirectly quoted someone who said :
[quoted text clipped - 15 lines]
> Roedy Green Canadian Mind Products
> The Java Glossaryhttp://mindprod.com

Thank you for this. I was able to do this without any help and I'm
glad about it.
Roedy Green - 19 Feb 2008 13:16 GMT
>> Draw this with a for loop
>>
>> xxxxxxxxxxxxxx
>>
>> Seehttp://mindprod.com/jgloss/jcheat.html

>Thank you for this. I was able to do this without any help and I'm
>glad about it.

Convert that is now a black box -- a method that draws N x's.

This gives you a new concetual tool to rethink the problem.  You need
to call THAT repeatedly. So that leaves two problems:

1. how many times.

2. how long each time.

Tackle them separately.
--

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
Roedy Green - 01 Mar 2008 02:23 GMT
>999999999
>
>I've seen it done in class but can't seem to remember.  There were
>only two for loops in the code.  Can someone help me with the code?

solve the problem of how to create just that row of 9s first.

Then figure out how to display an  list of any digit.

Then build your triangle.

You need only the simplest for loop.  See
http://mindprod.com/jgloss/jcheat.html

or your text.
--

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.