• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

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: 22815
132
Eclipse IDE Spring 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: 22815
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Exactly.
 
When people don’t understand what you are doing they call you crazy. But this tiny ad just doesn't care:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic