• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

String display without any loops

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how to display a string 'n' number of times without using any loops. here 'n' is user entered integer number.
 
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good idea, Gavin.

And welcome to JavaRanch, Yuva Rani.
 
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I guess its a matter of preference, but I normally find recursion easier to understand than loops.
 
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for answering my question!!
 
Ranch Hand
Posts: 1970
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic