Results 1 to 9 of 9
Thread: diamond shape
- 03-26-2012, 05:27 PM #1
Member
- Join Date
- Mar 2012
- Posts
- 6
- Rep Power
- 0
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 #2
Member
- Join Date
- Mar 2012
- Posts
- 6
- Rep Power
- 0
Re: diamond shape
hello?
- 03-27-2012, 07:50 PM #3
Re: diamond shape
something looks funny about your * pattern, are you sure you pasted it correctly?
- 03-27-2012, 08:27 PM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,604
- Blog Entries
- 7
- Rep Power
- 17
- 03-27-2012, 09:06 PM #5
Member
- Join Date
- Mar 2012
- Posts
- 6
- Rep Power
- 0
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 #6
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,619
- Rep Power
- 5
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 #7
Member
- Join Date
- Mar 2012
- Posts
- 6
- Rep Power
- 0
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 #8
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,619
- Rep Power
- 5
- 03-27-2012, 09:59 PM #9
Member
- Join Date
- Mar 2012
- Posts
- 6
- Rep Power
- 0
Re: diamond shape
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
Similar Threads
-
Diamond in java
By gareth in forum New To JavaReplies: 0Last Post: 11-17-2011, 02:27 PM -
ASCII art, drawing an asterisks diamond within dots.
By ajknight7498 in forum New To JavaReplies: 3Last Post: 11-10-2011, 11:20 PM -
how to change the shape of the JFrame to a oval shape
By kiki2009 in forum Java 2DReplies: 1Last Post: 04-02-2010, 12:48 PM -
Diamond Program?????
By Cubba27 in forum New To JavaReplies: 3Last Post: 11-19-2009, 08:15 PM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks