waltermilner

Untitled

Jun 22nd, 2016
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.42 KB | None | 0 0
  1. class Test {
  2. // calculate the golden mean as a continued fraction
  3.   public static void main(String[] args) {
  4.     System.out.println(term(1)); // 1.6180340557275543
  5.   }
  6.  
  7.   static double term( int count)
  8.   { // count is the depth of the recursion
  9.     if (count==20) return Double.MAX_VALUE; // stop at depth 20. 1/term will be very small
  10.     // otherwise, its 1 + 1/recursive call:
  11.    return (1+1/term(count+1));
  12.   }
  13. }
Advertisement
Add Comment
Please, Sign In to add comment