# Make a diamond shape

Hi.....I am having problem on coding and make a diamond shape with 9 rows.
so, 1st row has 1 star, 2nd row has 3 star, 3rd row has 5 star etc...

I got this so far but just dunno how to continue:

for ( int counter = 1; counter <= number; counter++ )
{
for ( int side = 1; counter <= side; --side )
System.out.print( ' ' );

for ( int side = 1; side <= number; side++ )

System.out.print( '*' );
System.out.println();

}

Anyone can advise? Thank you so much! I am a beginner, so please be patient~
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
Hi!

I think this one is a homework.

Here are some tips for creating a diamond shape.
1. Create a loop for the upper half of the diamond. And then another one for the lower half.
2. The number of "*" for every row increments by 2.
3. The number of " " for the first row =  # of rows / 2 - 1 (The 1 is for the asterisk). Then for the upper half, it will decrement by 1 for the succeeding rows .
For the lower half, it will increment by 1.

I hope I helped.

fave_17
0
Commented:
easier if you do the top half 1st, then the bottom half, try something like:

for (int i=1; i<number; i+=2)
{
for (int j=0; j<(number-i)/2; j++) System.out.print(' ');
for (int j=0; j<number; j++) System.out.print('*');
System.out.println();
}
for (int i=number; j>0; i-=2)
{
for (int j=0; j<(number-i)/2; j++) System.out.print(' ');
for (int j=0; j<number; j++) System.out.print('*');
System.out.println();
}

0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Author Commented:
When I modified mine to:
for ( int counter = 1; counter <= number; counter+=2 )
{
for ( int side = 0; side <= (number-counter)/2; side++ )
System.out.print( ' ' );

for ( int side = 0; side <= number; side++ )
System.out.print( '*' );
System.out.println();
}

System.out.println();

for ( int counter = number; counter >0; counter-=2 )
{
for ( int side = 0; side < (number-counter)/2; side++ )
System.out.print( ' ' );

for ( int side = 0; side < number; side++ )
System.out.print( '*' );
System.out.println();
}

It printed out...........

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

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

how come? Thanks
0
Commented:
>  for (int j=0; j<number; j++) System.out.print('*');

woops, should be drawing i stars, not number. that should be

for (int j=0; j<i; j++) System.out.print('*');
0
Author Commented:
objects,
thanks a lot, that helps me so much!
0
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.