The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
January 2002



This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.


The problem with your solution Matt

Posted by Hiran on January 25, 2002 at 5:19 PM

That's a much more elegant solution Matt, but it'll only handle 5 and 7 stars. I have a feeling that Imran needs to be able to accept any input for the number of stars. Even if he doesn't, and your solution will work for him, how would you have the application display x number of stars, where x is an odd number? I'm sure there's a more elegant and still quite simple solution than mine.

> Heck, wouldn't that be overkill, given the specification? Don't you know anything about Extreme Programming? Here's the solution:

> static void drawDiamonds(int starz)
> {
> switch(starz)
> {
> case 5:
> System.out.println(" *\n ***\n*****\n ***\n *");
> break;
> case 7:
> System.out.println(" *\n ***\n *****\n*******\n *****\n ***\n *");
> break;
> default:
> throw new IllegalArgumentException("Hey man, I can't handle " +
> starz + " stars!" );
> }
> }

> ;-)


Sponsored Links

Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us