WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions java/Fibonacci.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* This program uses a recursive function to find the number present at the given position in the Fibonacci series */

import java.util.*;

public class Fibonacci {
public static long fib(long n) {
if ((n == 0) || (n == 1))
return n;
else
return fib(n - 1) + fib(n - 2);
}
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Please Enter the Position:");
int pos=sc.nextInt();
if (pos == 1)
System.out.println("The " + pos + "st fibonacci number is: " + fib(pos));
if (pos == 2)
System.out.println("The " + pos + "nd fibonacci number is: " + fib(pos));
if (pos == 3)
System.out.println("The " + pos + "rd fibonacci number is: " + fib(pos));
else
System.out.println("The " + pos + "th fibonacci number is: " + fib(pos));
}
}