Results 1 to 9 of 9
Like Tree1Likes
  • 1 Post By JosAH

Thread: diamond shape

  1. #1
    hussien is offline Member
    Join Date
    Mar 2012
    Posts
    6
    Rep Power
    0

    Default 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.

  2. #2
    hussien is offline Member
    Join Date
    Mar 2012
    Posts
    6
    Rep Power
    0

    Default Re: diamond shape

    hello?

  3. #3
    sehudson's Avatar
    sehudson is offline Senior Member
    Join Date
    Mar 2010
    Posts
    354
    Rep Power
    5

    Default Re: diamond shape

    something looks funny about your * pattern, are you sure you pasted it correctly?

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,336
    Blog Entries
    7
    Rep Power
    20

    Default Re: diamond shape

    Quote Originally Posted by hussien View Post
    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 ;-)
    DarrylBurke likes this.
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    hussien is offline Member
    Join Date
    Mar 2012
    Posts
    6
    Rep Power
    0

    Default Re: diamond shape

    sorry , it was my fault
    here is screenshot of the problem
    ImageShack® - Online Photo and Video Hosting

  6. #6
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default 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)

  7. #7
    hussien is offline Member
    Join Date
    Mar 2012
    Posts
    6
    Rep Power
    0

    Default 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.

  8. #8
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default Re: diamond shape

    Quote Originally Posted by hussien View Post
    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.

  9. #9
    hussien is offline Member
    Join Date
    Mar 2012
    Posts
    6
    Rep Power
    0

    Default Re: diamond shape

    Quote Originally Posted by doWhile View Post
    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

Similar Threads

  1. Diamond in java
    By gareth in forum New To Java
    Replies: 0
    Last Post: 11-17-2011, 02:27 PM
  2. ASCII art, drawing an asterisks diamond within dots.
    By ajknight7498 in forum New To Java
    Replies: 3
    Last Post: 11-10-2011, 11:20 PM
  3. Replies: 1
    Last Post: 04-02-2010, 12:48 PM
  4. Diamond Program?????
    By Cubba27 in forum New To Java
    Replies: 3
    Last Post: 11-19-2009, 08:15 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •