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 * ** *** **** ***** **** *** ** *
Joined: Dec 20, 2000
Lets see what you have so far and maybe someone can point ya in the right direction.
Joined: Feb 22, 2001
Hi ADNAN 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).]
Joined: Mar 06, 2001
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
Joined: Mar 26, 2001
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).]
Joined: Jan 24, 2001
Lawrence, To create your int named "count", why not just do it like so: <h4>int count = Integer.parseInt( args ) ;</h4> This is alot easier than converting the string to an Integer object and then to an int...it skips an unnecessary step. ------------------