# Urgent: Help Required With Nested For Loops

Matthew Higgs
Greenhorn
Posts: 5
Ok, I need to design a program that creates a diamond shape using *'s

This is the one I created to do a triangle:
*
**
***
**
*
Can anyone help me... the program will ask how big the diamond is to be, the draw it... for example:
I input 5 it will look like this

Matthew Higgs
Greenhorn
Posts: 5
Please can anyone help... this is really, really urgent.

Rob Ross
Bartender
Posts: 2205
Well, why don't you try breaking up your problem into a left side loop and a right side loop, within each existing loop, since you're already breaking up the printing into a top half and bottom half?
Rob

Matthew Higgs
Greenhorn
Posts: 5
I've come up with this, but it doesn't work. It draws a diamond but not the right size.

Matthew Higgs
Greenhorn
Posts: 5
Doesn't matter now anyway I've figured it out:
private void outputDia()
{
for (int i = size/2; i >= 0; i--)
{
for (int j = 0; j <= i; j++)
{
outputBox.print(" ");
}
for (int j = 0; j < (2*(size/2 - i)+1); j++)
{
outputBox.print("*");
}
outputBox.skipLine(1);
}
for (int i = 1; i <= size/2; i++)
{
for (int j = 0; j <= i; j++)
{
outputBox.print(" ");
}
for (int j = 0; j < (2*(size/2 - i)+1); j++)
{
outputBox.print("*");
}
outputBox.skipLine(1);
}
}
}
That's if anyone was interested.

Rob Ross
Bartender
Posts: 2205
Good job! You got it working. That's good thing.

Rob

Marilyn de Queiroz
Sheriff
Posts: 9065
12
I knew you could figure it out. You had a good start.

Cindy Glass
"The Hood"
Sheriff
Posts: 8521
MattHiggs,
Your displayed name should be 2 separate names with more than 1 letter each. We really want this to be a professional forum and would prefer that you use your REAL name.
Thanks,
Cindy

Matthew Higgs
Greenhorn
Posts: 5
better?

Cindy Glass
"The Hood"
Sheriff
Posts: 8521
Much better .
However - for razzing the bartender - 50 points from Higgs House.