Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Mike Amling Newsgroups: comp.lang.java.programmer Subject: Re: PRINTING DIAMOND SHAPE WITH LOOPS! Date: Fri, 01 Nov 2013 09:59:25 -0500 Lines: 98 Message-ID: References: <4wTWc.18629$cx.18110@bignews4.bellsouth.net> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net stEF3Y1oRJPgXAXdtJPXCAsL1+FAmFZ8E58t69a9diZMvI83e2 Cancel-Lock: sha1:pb4g2Hxb+edY1LRvtUbwHZufbZA= User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:24.0) Gecko/20100101 Thunderbird/24.1.0 In-Reply-To: Xref: csiph.com comp.lang.java.programmer:26467 On 11/1/13 3:30 AM, jyothi.m1089@gmail.com wrote: > On Wednesday, August 25, 2004 11:59:37 AM UTC+5:30, Liz wrote: >> "Hal Rosser" wrote in message >> news:4wTWc.18629$cx.18110@bignews4.bellsouth.net... >>> >>> "Jay Dean" wrote in message >>> news:bd7dee67.0408241759.3884e4e9@posting.google.com... >>>> I need simple nested loops (either for, or while) code for a method to >>>> print a diamond shaped stars for n stars, where n is odd. >>>> Example. n=9 would produce >>>> >>>> * >>>> *** >>>> ***** >>>> ******* >>>> ********* >>>> ******* >>>> ***** >>>> **** >>>> * > can you please explain the logic of this program.... I haven't looked at the program, but looking at the diamond I see the first and last lines have one star, but the second and next-to-last have three stars and four stars respectively. I assume the four-star line was supposed to have three stars. The number of lines to be written is n, so we might hope that an outermost loop would look like for (int jj=0; jj=0; ) { System.out.print(' '); } for (int kk=n-Math.abs(2*jj-n)+1; --kk>=0; ) { System.out.print('*'); } } Mike Amling -- "Fiat lux" is the Big Bang in Latin.