Fibonacci sequence Java
•
Java
</span><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">void</span><span style="color: #000000;"> main(String agrs[])
{
</span><span style="color: #0000ff;">for</span>(<span style="color: #0000ff;">int</span> j=<span style="color: #800080;">1</span>;j<=<span style="color: #800080;">15</span>;j++<span style="color: #000000;">)
Sy<a href="https://www.jb51.cc/tag/stem/" target="_blank" class="keywords">stem</a>.</span><span style="color: #0000ff;">out</span><span style="color: #000000;">.println(fobi(j));
}
</span><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">int</span> fobi(<span style="color: #0000ff;">int</span><span style="color: #000000;"> i)
{
</span><span style="color: #0000ff;">if</span>(i<=<span style="color: #800080;">2</span>) <span style="color: #0000ff;">return</span> <span style="color: #800080;">1</span><span style="color: #000000;">;
</span><span style="color: #0000ff;">return</span> fobi(i-<span style="color: #800080;">1</span>) + fobi(i-<span style="color: #800080;">2</span><span style="color: #000000;">);
}
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码