• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Momo Sawada
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • 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!!!
 
Rob Spoor
Sheriff
Pie
Posts: 20559
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • 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
  • 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!!!
 
Michel ten Voorde
Greenhorn
Posts: 26
Android Linux Opera
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
Pie
Posts: 20559
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Exactly.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic