• 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

what can i do to make my code right???

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello again!!! and thanks to all who helped me greatly in my previous questions....
right now... i have a teensy problem...
this code...



produces an output something like this...
Entering: 4
Entering: 3
Entering: 2
Entering: 1
Returning: 1
Returning: 2
Entering: 1
Returning: 1
Returning: 6
Entering: 2
Entering: 1
Returning: 1
Returning: 2
Entering: 1
Returning: 1
Returning: 24
Entering: 3
Entering: 2
Entering: 1
Returning: 1
Returning: 2
Entering: 1
Returning: 1
Returning: 6
Entering: 2
Entering: 1
Returning: 1
Returning: 2
Entering: 1
Returning: 1
24

but how can i make it something like this?
Entering: 4
Entering: 3
Entering: 2
Entering: 1
Returning: 1
Returning: 2
Returning: 6
Returning: 24
24

I've tried moving the print lines all over the code block... but i just can't find where i should put it...
please... can anyone help me???
Thanks a lot!!! really!!!
 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In your compute method you're calling compute(n-1) twice. Cache the value and see the difference:
 
Momo Sawada
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it says something like stackoverflowerror.... endlessly...
oh well.. i guess i better look more closely...
thank you for the advice!!! gotta get working on it!!!
 
Greenhorn
Posts: 29
Android Opera Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rob's code was meant to replace only line 15 and 16 of your code. That way, it should give run and return the output you'd expect.
 
Rob Spoor
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Exactly.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic