aspose file tools*
The moose likes Beginning Java and the fly likes Urgent: Help Required With Nested For Loops Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Urgent: Help Required With Nested For Loops" Watch "Urgent: Help Required With Nested For Loops" New topic
Author

Urgent: Help Required With Nested For Loops

Matthew Higgs
Greenhorn

Joined: Feb 05, 2002
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

Joined: Feb 05, 2002
Posts: 5
Please can anyone help... this is really, really urgent.
Rob Ross
Bartender

Joined: Jan 07, 2002
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


Rob
SCJP 1.4
Matthew Higgs
Greenhorn

Joined: Feb 05, 2002
Posts: 5
I've come up with this, but it doesn't work. It draws a diamond but not the right size.
I've had two attempts, can anyone please help me.
Matthew Higgs
Greenhorn

Joined: Feb 05, 2002
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

Joined: Jan 07, 2002
Posts: 2205
Good job! You got it working. That's good thing.

Rob
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9046
    
  10
I knew you could figure it out. You had a good start.


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
MattHiggs,
Please change your name to be compliant with JavaRanch's naming policy.
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


"JavaRanch, where the deer and the Certified play" - David O'Meara
Matthew Higgs
Greenhorn

Joined: Feb 05, 2002
Posts: 5
better?
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
Much better .
However - for razzing the bartender - 50 points from Higgs House.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Urgent: Help Required With Nested For Loops