Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #26464
| Newsgroups | comp.lang.java.programmer |
|---|---|
| Date | 2013-11-01 01:30 -0700 |
| References | <bd7dee67.0408241759.3884e4e9@posting.google.com> <4wTWc.18629$cx.18110@bignews4.bellsouth.net> <llWWc.228978$eM2.215971@attbi_s51> |
| Message-ID | <ecaee893-0ad6-48a6-b345-24a33436b4df@googlegroups.com> (permalink) |
| Subject | Re: PRINTING DIAMOND SHAPE WITH LOOPS! |
| From | jyothi.m1089@gmail.com |
On Wednesday, August 25, 2004 11:59:37 AM UTC+5:30, Liz wrote:
> "Hal Rosser" <hmrosser@bellsouth.net> wrote in message
> news:4wTWc.18629$cx.18110@bignews4.bellsouth.net...
> >
> > "Jay Dean" <fresh1700@yahoo.com> 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
> > >
> > > *
> > > ***
> > > *****
> > > *******
> > > *********
> > > *******
> > > *****
> > > ****
> > > *
> > > I have STRUGGLED with this for over three days in a row and my head
> > > aches!
> > > I tried with nested loops, and conditions but the results were not
> > > encouraging.
> > > I am a novice in Java and need help with simple nested loops to
> > > construct this. Thanks in advance for your help !!
> > >
> > > Jay Dean
> >
> > Jay,
> > Being a beginner at programming, it may be a good idea to plan it out
> first.
> > you typed out what you want your program to do, so you should make note of
> > what you did.
> > For instance, note that the number of spaces before the "*" starts at a
> > maximum value and decreases by one after each print.
> > Also note the number of "*"s increase from one to a maximum value - then
> > decreases by one to one.
> > You're on the right track of using nested loops - you need to increment
> one
> > value and decrement another value.
> > Its a good exercise in planning your app.
> > Use flowcharts to plan if it makes things clearer for you.
> > Plan first - then write the code.
> > Hope this helps
> > Hal
> >
> ---------------------
>
> class Test7
> {
> public static final void main( String[] args )
> {
> int n = Integer.parseInt( args[ 0 ] );
> for ( int i = 1; i <= n; i += 2 )
> {
> for ( int k = 0; k < ( n - i ); k += 2 )
> System.out.print( " " );
> for ( int j = 0; j < ( ( i * 2 ) - 1 ); j += 2 )
> System.out.print( "*" );
> System.out.println( "" );
> }
> for ( int i = 1; i <= n; i += 2 )
> {
> for ( int k = 1; k < i; k += 2 )
> System.out.print( " " );
> for ( int j = 0; j <= ( n - i ); j++ )
> System.out.print( "*" );
> System.out.println( "" );
> }
> }
> }
can you please explain the logic of this program....
Back to comp.lang.java.programmer | Previous | Next — Next in thread | Find similar | Unroll thread
Re: PRINTING DIAMOND SHAPE WITH LOOPS! jyothi.m1089@gmail.com - 2013-11-01 01:30 -0700
Re: PRINTING DIAMOND SHAPE WITH LOOPS! rossum <rossum48@coldmail.com> - 2013-11-01 13:03 +0000
Re: PRINTING DIAMOND SHAPE WITH LOOPS! Mike Amling <mamling@chaff.us> - 2013-11-01 09:59 -0500
Re: PRINTING DIAMOND SHAPE WITH LOOPS! Roedy Green <see_website@mindprod.com.invalid> - 2013-11-01 18:32 -0700
Re: PRINTING DIAMOND SHAPE WITH LOOPS! pchristor@yahoo.co.uk - 2013-11-12 05:21 -0800
Re: PRINTING DIAMOND SHAPE WITH LOOPS! Lew <lewbloch@gmail.com> - 2013-11-27 15:57 -0800
Re: PRINTING DIAMOND SHAPE WITH LOOPS! Arne Vajhøj <arne@vajhoej.dk> - 2013-11-27 19:21 -0500
Re: PRINTING DIAMOND SHAPE WITH LOOPS! pchristor@yahoo.co.uk - 2013-11-28 17:45 -0800
Re: PRINTING DIAMOND SHAPE WITH LOOPS! Arne Vajhøj <arne@vajhoej.dk> - 2013-11-28 21:10 -0500
Re: PRINTING DIAMOND SHAPE WITH LOOPS! pchristor@yahoo.co.uk - 2013-11-29 03:03 -0800
Re: PRINTING DIAMOND SHAPE WITH LOOPS! Joerg Meier <joergmmeier@arcor.de> - 2013-11-29 12:33 +0100
Re: PRINTING DIAMOND SHAPE WITH LOOPS! pchristor@yahoo.co.uk - 2013-11-29 09:01 -0800
Re: PRINTING DIAMOND SHAPE WITH LOOPS! Arne Vajhøj <arne@vajhoej.dk> - 2013-11-29 13:15 -0500
Re: PRINTING DIAMOND SHAPE WITH LOOPS! pchristor@yahoo.co.uk - 2013-11-29 17:06 -0800
Re: PRINTING DIAMOND SHAPE WITH LOOPS! pchristor@yahoo.co.uk - 2013-11-29 17:24 -0800
Re: PRINTING DIAMOND SHAPE WITH LOOPS! Arne Vajhøj <arne@vajhoej.dk> - 2013-11-29 20:59 -0500
Re: PRINTING DIAMOND SHAPE WITH LOOPS! pchristor@yahoo.co.uk - 2013-11-30 06:57 -0800
Re: PRINTING DIAMOND SHAPE WITH LOOPS! Arne Vajhøj <arne@vajhoej.dk> - 2013-11-30 10:31 -0500
Re: PRINTING DIAMOND SHAPE WITH LOOPS! Lew <lewbloch@gmail.com> - 2013-12-02 15:32 -0800
Re: PRINTING DIAMOND SHAPE WITH LOOPS! pchristor@yahoo.co.uk - 2013-12-04 03:45 -0800
Re: PRINTING DIAMOND SHAPE WITH LOOPS! Arne Vajhøj <arne@vajhoej.dk> - 2013-12-09 21:10 -0500
Re: PRINTING DIAMOND SHAPE WITH LOOPS! pchristor@yahoo.co.uk - 2013-12-05 00:15 -0800
Re: PRINTING DIAMOND SHAPE WITH LOOPS! Arne Vajhøj <arne@vajhoej.dk> - 2013-12-09 21:14 -0500
Re: PRINTING DIAMOND SHAPE WITH LOOPS! Joerg Meier <joergmmeier@arcor.de> - 2013-11-29 19:58 +0100
Re: PRINTING DIAMOND SHAPE WITH LOOPS! pchristor@yahoo.co.uk - 2013-11-29 17:12 -0800
Re: PRINTING DIAMOND SHAPE WITH LOOPS! Joerg Meier <joergmmeier@arcor.de> - 2013-11-30 02:55 +0100
Re: PRINTING DIAMOND SHAPE WITH LOOPS! Arne Vajhøj <arne@vajhoej.dk> - 2013-11-29 21:01 -0500
Re: PRINTING DIAMOND SHAPE WITH LOOPS! Lew <lewbloch@gmail.com> - 2013-12-02 15:31 -0800
Re: PRINTING DIAMOND SHAPE WITH LOOPS! Arne Vajhøj <arne@vajhoej.dk> - 2013-11-29 12:48 -0500
csiph-web