Groovy web console

subscribe to the feed Subscribe
to this
site
fibonacci (via #groovywebconsole)
tweet this snippet Tweet
this
script

fibonacci

Published 2 months ago by Eduardo
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
public BigDecimal fibonacci(BigDecimal n) {
    if (n <= 1) return n
    
    return fibonacci(n-1) + fibonacci(n-2)    
}

fibonacci(7)