• 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
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

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: 22701
129
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: 22701
129
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.
 
Where does a nanny get ground to air missles? Protect this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic