This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes nested  loop ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "nested  loop ?" Watch "nested  loop ?" New topic

nested loop ?


Joined: Feb 26, 2001
Posts: 6
Q):- Write a program that ask the user to enter the size of triangle to print out (an integer from 1 to 50, then print the triangle by printing a series of lines with asterisks. The first line wil have one asterisk,the next two,etc. each line having one more asterisk thaan the previous line up to the number entered by the user. on the next line print one liess asterisk and continue by decreasing the number of asterisks by one for each successive line until only one asterisk is printed. Hint: use nested loop. for example if user input 5 the output would be
Andy Ceponis
Ranch Hand

Joined: Dec 20, 2000
Posts: 782
Lets see what you have so far and maybe someone can point ya in the right direction.
Siva Prasad
Ranch Hand

Joined: Feb 22, 2001
Posts: 104
To get the required output
In this example
look at the number of columns - 5, dont they represent the no. u entered. At each iteration, you print that character that many no. of times.
1st Iteration - print '*' 1 time(s)
2nd Iteration - print '*' 2 times
3rd Iteration - print '*' 3 times
so on...
so for printing '*' n times you must use another loop to achieve this.

Hope this helps
(edited by Cindy to add formatting)
[This message has been edited by Cindy Glass (edited March 26, 2001).]
usman ahmad
Ranch Hand

Joined: Mar 06, 2001
Posts: 46
This is one Big nested loop. Siva could you please elaborate a bit more so that I can also understand fully.Thanks a lot.
Lawrence Thurman

Joined: Mar 26, 2001
Posts: 3
Try this out - Yeah it is a little more involved but
it will work just copy and paste

[This message has been edited by Marilyn deQueiroz (edited March 27, 2001).]
ryan burgdorfer
Ranch Hand

Joined: Jan 24, 2001
Posts: 219
To create your int named "count", why not just do it like so:
<h4>int count = Integer.parseInt( args[0] ) ;</h4>
This is alot easier than converting the string to an Integer object and then to an skips an unnecessary step.
  • Ryan Burgdorfer
  • Java Acolyte in
  • Columbus, OH USA

<UL TYPE=SQUARE><I><LI>Ryan Burgdorfer<BR><LI>Java Acolyte</I></UL>
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: nested loop ?
It's not a secret anymore!