File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes what can i do to make my code right??? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "what can i do to make my code right???" Watch "what can i do to make my code right???" New topic
Author

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

Momo Sawada
Greenhorn

Joined: Dec 10, 2010
Posts: 24
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

Joined: Oct 27, 2005
Posts: 19649
    
  18

In your compute method you're calling compute(n-1) twice. Cache the value and see the difference:


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Momo Sawada
Greenhorn

Joined: Dec 10, 2010
Posts: 24
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

Joined: Dec 30, 2010
Posts: 26

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

Joined: Oct 27, 2005
Posts: 19649
    
  18

Exactly.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: what can i do to make my code right???
 
Similar Threads
Question48 of Valentin Crettaz's mock exam
Indenting output streams
how to complete this code?
Stacks
Nested Loops