Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Test {
- // calculate the golden mean as a continued fraction
- public static void main(String[] args) {
- System.out.println(term(1)); // 1.6180340557275543
- }
- static double term( int count)
- { // count is the depth of the recursion
- if (count==20) return Double.MAX_VALUE; // stop at depth 20. 1/term will be very small
- // otherwise, its 1 + 1/recursive call:
- return (1+1/term(count+1));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment