| Author |
String display without any loops
|
yuva rani
Greenhorn
Joined: Mar 17, 2008
Posts: 14
|
|
|
how to display a string 'n' number of times without using any loops. here 'n' is user entered integer number.
|
 |
Gavin Tranter
Ranch Hand
Joined: Jan 01, 2007
Posts: 333
|
|
You could try recurssion. If you do a search of the ranch, I am sure there are plenty of topics mentioning recurssion, and plenty on the web in general. [ May 14, 2008: Message edited by: Gavin Tranter ]
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32608
|
|
Good idea, Gavin. And welcome to JavaRanch, Yuva Rani.
|
 |
Jeff Storey
Ranch Hand
Joined: Apr 07, 2007
Posts: 230
|
|
Yuva, Here is a recursive example that might help you for your problem. Keep in mind this is just one possible solution (a loop is a much better idea though since recursion creates a bunch of calls on the stack and can often be harder to understand). Hope this helps, Jeff
|
 |
Garrett Rowe
Ranch Hand
Joined: Jan 17, 2006
Posts: 1295
|
|
|
I guess its a matter of preference, but I normally find recursion easier to understand than loops.
|
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
|
 |
Balasubramanian Chandrasekaran
Ranch Hand
Joined: Nov 28, 2007
Posts: 215
|
|
Originally posted by Jeff Storey: Yuva, Here is a recursive example that might help you for your problem. Keep in mind this is just one possible solution (a loop is a much better idea though since recursion creates a bunch of calls on the stack and can often be harder to understand). Hope this helps, Jeff
Jeff i think you missed one small thing in your code instead of
|
 |
yuva rani
Greenhorn
Joined: Mar 17, 2008
Posts: 14
|
|
|
Thank you for answering my question!!
|
 |
Peter Chase
Ranch Hand
Joined: Oct 30, 2001
Posts: 1970
|
|
Originally posted by Jeff Storey: Here is a recursive example that might help you for your problem.
Jeff - basically, you just did this guy's homework for him. At JavaRanch we ask LetThemDoTheirOwnHomework. By all means give hints (e.g. "you could consider recursion"), but not fully -worked answers.
|
Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.<br /> <br />#:^P
|
 |
 |
|
|
subject: String display without any loops
|
|
|