Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Jesse Black   on May 11 In Java Category.

  
Question Answered By: Ryan Evans   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.

Share: