Fibonacci numbers in Groovy, Java
Example for versions
Groovy 1.7,
Sun Java 6,
gcj 3.4.5
This example uses recursive definition of Fibonacci numbers.
public class Fibonacci {
static int fibonacci(int n)
{
return (n<=2 ? 1 : fibonacci(n-1) + fibonacci(n-2));
}
public static void main(String[] args)
{
for (int n=1; n<=16; n++)
System.out.print(fibonacci(n)+", ");
System.out.println("...");
}
}
Comments
]]>blog comments powered by Disqus
]]>