id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

jebbert@volusia.k12.fl.us > goldenRatio
prev  |  next  |  chance

The "golden ratio" can be calculated using a recursive formula. If we define g as the golden ratio, we note that g=1+1/g. Using this formula recursively, we can theoretically calculate g to any degree of accuracy. Write a method that returns the result of howMany recursive steps into this recursive formula. For example: goldenRatio(2) returns 1.5 because 1+1/(1+1/(1)) is 1.5. If howMany=0, just return 1.


goldenRatio(0) → 1.0
goldenRatio(1) → 2.0
goldenRatio(2) → 1.5

...Save, Compile, Run (ctrl-enter)

public double goldenRatio(int howMany) { }

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Java Help

Misc Code Practice

Difficulty: 380

Copyright Nick Parlante 2017 - privacy