Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!

# nested loop ?

Greenhorn
Posts: 6
ASSALAM-O-ALAKUM:-
I HAVE A QUESTION ABOUT NESTED LOOP WHIHC I CAN NOT UNEDERSTAND.
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
Posts: 782
Lets see what you have so far and maybe someone can point ya in the right direction.

Ranch Hand
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).]

Ranch Hand
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.
regards
Usman

Lawrence Thurman
Greenhorn
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
Posts: 219
Lawrence,
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 int...it skips an unnecessary step.
------------------
• Ryan Burgdorfer
• Java Acolyte in
• Columbus, OH USA