# diamond shape

• 03-26-2012, 05:27 PM
hussien
diamond shape
hello,I have just started learning java and I was asked question I can not solve it.so I want someone expert in java to help me.
the question is:
Write a program that prints a diamond with a plus within it, given the height of the diamond. The outer-most shape is a normal
diamond shape, the middle row of the shape will be a row filled with stars (making the horizontal dash of the plus sign), and in
all the remaining rows the middle element of that row will have a star (making the vertical dash of the plus sign). Observe the
following examples.
For n=11, the output will look like:
*
***
* * *
* * *
* * *
***********
* * *
* * *
* * *
***
*
For n=7, the output will look like:
*
***
* * *
*******
* * *
***
*
For n=3, the output will look like:
*
***
*
For n=1, the output will look like:
*
Only consider odd sizes.
• 03-27-2012, 07:49 PM
hussien
Re: diamond shape
hello?
• 03-27-2012, 07:50 PM
sehudson
Re: diamond shape
something looks funny about your * pattern, are you sure you pasted it correctly?
• 03-27-2012, 08:27 PM
JosAH
Re: diamond shape
Quote:

Originally Posted by hussien
For n=11, the output will look like:
*
***
* * *
* * *
* * *
***********
* * *
* * *
* * *
***
*

That' not a diamond; that's a dead mole, impaled to a wall by a javelin.

kind regards,

Jos ;-)
• 03-27-2012, 09:06 PM
hussien
Re: diamond shape
sorry , it was my fault
here is screenshot of the problem
ImageShack® - Online Photo and Video Hosting
• 03-27-2012, 09:24 PM
doWhile
Re: diamond shape
So, you expect us to take valuable time out of our day to help you out when you've shown you've done nothing more than post a photo of your homework assignment? Pretty rude if you ask me - expecting folks to invest more time than you in what is your problem. Here's my suggestion: make an effort, ask a specific question, post some code, and use the resources available to you (this question - or those like it - have been asked on the forums ad nauseum)
• 03-27-2012, 09:49 PM
hussien
Re: diamond shape
I have not post it here until I had made numerous trials to do it.I made some of it but it still not totally right .(But if you want specific question)I just want to know how to make gaps inside the triangles.
• 03-27-2012, 09:55 PM
doWhile
Re: diamond shape
Quote:

Originally Posted by hussien
I have not post it here until I had made numerous trials to do it.I made some of it but it still not totally right .(But if you want specific question)I just want to know how to make gaps inside the triangles.

Then post what you tried, and describe where you are stuck in excruciating detail. We are not mind readers (at least some of us aren't), and cannot know what you've tried or where you are stuck - information necessary to guide you - unless you tell us.
• 03-27-2012, 09:59 PM
hussien
Re: diamond shape
Quote:

Originally Posted by doWhile
Then post what you tried, and describe where you are stuck in excruciating detail. We are not mind readers (at least some of us aren't), and cannot know what you've tried or where you are stuck - information necessary to guide you - unless you tell us.

Ok here what I've done

for ( int i = 1; i <= n; i += 2 )
{
for ( int j = 0; j < ( n - i ); j += 2 )
System.out.print( " " );
for ( int k = 0; k < ( ( i * 2 ) - 1 ); k += 2 )
System.out.print( "*" );
System.out.println( "" );
}
for ( int i = 1; i <= n; i += 2 )
{
for ( int j = 1; j < i; j += 2 )
System.out.print( " " );
for ( int k = 0; k <= ( n - i ); k++ )
System.out.print( "*" );
System.out.println( "" );
}

it compile but it prints whole diamond not hollow one as it appears in exercise