Jump to content

Nested for Loop help!!!

- - - - -

  • Please log in to reply
3 replies to this topic

#1
hotdog916

hotdog916

    Newbie

  • Members
  • Pip
  • 2 posts
I need help with part of some codes I'm writing. It outputs the spaceneedle. I need to draw out the top and bottom of it. Here is the picture.

__/||\__
__/:::||:::\__
__/::::::||::::::\__
__/:::::::::||:::::::::\__

The bottom looks like this:

\_/\/\/\/\/\/\/\/\/\/\/\_/
\_/\/\/\/\/\/\/\/\/\_/
\_/\/\/\/\/\/\/\_/
\_/\/\/\/\/\_/

Hope these look right here...

---------- Post added at 05:51 PM ---------- Previous post was at 05:43 PM ----------

Hmm they didn't turn out looking right after all... But it's supposed to look like the SpaceNeedle from Seattle. Any help would be appreciated!

#2
Vaielab

Vaielab

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 547 posts
So what are your guess... do you have something to start with?

#3
hotdog916

hotdog916

    Newbie

  • Members
  • Pip
  • 2 posts
Here is what I have... they're not loops though!

public static void drawTop() // draw the top of the space needle
{

System.out.println (" __/||\\__ ");
System.out.println (" __/:::||:::\\__ ");
System.out.println (" __/::::::||::::::\\__ ");
System.out.println ("__/:::::::::||:::::::::\\__");

}

public static void drawSlashes() // draw slashes in the output
{

System.out.println ("\\_/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\_/");
System.out.println (" \\_/\\/\\/\\/\\/\\/\\/\\/\\/\\_/ ");
System.out.println (" \\_/\\/\\/\\/\\/\\/\\/\\_/ ");
System.out.println (" \\_/\\/\\/\\/\\/\\_/ ");


}

#4
Sinipull

Sinipull

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 386 posts
If the top and bottom have n layers. You need one loop to repeat the other loop n times, which prints the colons n*3 times for both sides.
During the printing, you need to place __/ and || and \__ where appropriate.

Something like this in pseudocode:

layers = 3;
for(row = 0; row < layers; row++){
    print("__/");
    for(column = 0; column < row*3; column++)
         print(":");
    print("||");
    for(column = 0; column < row*3; column++)
         print(":");
    print("\\__");
}

you need to add the right amount of whitespace too.



            __/||\__ 
         __/:::||:::\__ 
      __/::::::||::::::\__ 
   __/:::::::::||:::::::::\__
   \_/\/\/\/\/\/\/\/\/\/\/\_/ 
     \_/\/\/\/\/\/\/\/\/\_/ 
       \_/\/\/\/\/\/\/\_/ 
         \_/\/\/\/\/\_/
The bottom uses the same logic, but is easier to implement, because it has no middle separator.
.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users