Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Diamond in #

  Asked By: Jesse    Date: May 11    Category: Java    Views: 823
  

can anyone suggest how I can make a diamond in # an empty one and a filled one?

Share: 

 

2 Answers Found

 
Answer #1    Answered By: Lenora Green     Answered On: May 11

I want to display on the screen something like this. I want one filled and one
empty (just the outline of a diamond!


#
####
########
####
#

 
Answer #2    Answered By: Ryan Evans     Answered On: May 11

You are going to need to use a loop, and a String that adds to it self.

Something like (assuming you want the diamond to 7 long

String blah = "";
for (int i = 0; i <= 7; i ++){
blah = blah + "#\n";
}

This isn't a very pretty way of dealing with your problem, and it
doesn't make a full diamond, only a triangle. If you want to make a
diamond you need to be able to shrink the string too.

However it would make something roughly to what you have imaged here.
If you want it to be a real diamon shape (starts off small, gets big in
the middle and then shrinks), I would look at making use of the % function.

The hollow one is slightly harder, you have to add a simple logic
function which will only add a hash in at the right spots.

I won't show you the rest, you should be able to finish the assignment
from here.

 
Didn't find what you were looking for? Find more on Diamond in # Or get search suggestion and latest updates.




Tagged: