Click here to Skip to main content
14,325,352 members
Rate this:
Please Sign up or sign in to vote.
See more:
I need a Java code solution to produce the following pattern:
The - can be replaced with spaces.[Sorry the preview does not look good so follow that the pattern actually should be shaped like a rhombus]

No methods to be used. Straightforward code with a main function

What I have tried:

I have tried some codes but the shape of the pattern does not follow the Rhombus.
Updated 31-Dec-18 4:52am
Rate this:
Please Sign up or sign in to vote.

Solution 1

Most probably copy rigthed by OG, @OriginalGriff:
We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!

If you meet a specific problem, then please ask about that and we will do our best to help. But we aren't going to do it all for you!

Maybe you Show what you really tried? I mean some code?
Rate this:
Please Sign up or sign in to vote.

Solution 2

Think about what you are trying to create. The pattern is quite simple: an asterisk, followed by some dashes (between 0 and 21), followed by an asterisk. Use a counter that counts up until it reaches the maximum value, and then counts down back to zero.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100