Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #30575
| X-Received | by 10.42.164.133 with SMTP id g5mr39854224icy.16.1418802357508; Tue, 16 Dec 2014 23:45:57 -0800 (PST) |
|---|---|
| X-Received | by 10.140.22.199 with SMTP id 65mr821332qgn.4.1418802357374; Tue, 16 Dec 2014 23:45:57 -0800 (PST) |
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!us.feeder.erje.net!news.glorb.com!h15no23753991igd.0!news-out.google.com!r1ni59qat.1!nntp.google.com!n8no208039qaq.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail |
| Newsgroups | comp.lang.java.programmer |
| Date | Tue, 16 Dec 2014 23:45:57 -0800 (PST) |
| In-Reply-To | <bd7dee67.0408241759.3884e4e9@posting.google.com> |
| Complaints-To | groups-abuse@google.com |
| Injection-Info | glegroupsg2000goo.googlegroups.com; posting-host=213.55.107.174; posting-account=QothSgoAAAAKUF6sGcomUnWkSNPcO51s |
| NNTP-Posting-Host | 213.55.107.174 |
| References | <bd7dee67.0408241759.3884e4e9@posting.google.com> |
| User-Agent | G2/1.0 |
| MIME-Version | 1.0 |
| Message-ID | <bfe1ebd3-fe8f-4835-af37-e33d4edf0eba@googlegroups.com> (permalink) |
| Subject | Re: PRINTING DIAMOND SHAPE WITH LOOPS! |
| From | mastewalchekole2007@gmail.com |
| Injection-Date | Wed, 17 Dec 2014 07:45:57 +0000 |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Xref | csiph.com comp.lang.java.programmer:30575 |
Show key headers only | View raw
On Tuesday, August 24, 2004 6:59:36 PM UTC-7, Jay Dean wrote:
> 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
for (int i = 1; i < 10; i += 2) {
for (int j = 0; j < 9 - i / 2; j++)
System.out.print(" ");
for (int j = 0; j < i; j++)
System.out.print("*");
System.out.print("\n");
}
for (int i = 7; i > 0; i -= 2) {
for (int j = 0; j < 9 - i / 2; j++)
System.out.print(" ");
for (int j = 0; j < i; j++)
System.out.print("*");
System.out.print("\n");
}
}
}
Back to comp.lang.java.programmer | Previous | Next | Find similar | Unroll thread
Re: PRINTING DIAMOND SHAPE WITH LOOPS! mastewalchekole2007@gmail.com - 2014-12-16 23:45 -0800
csiph-web