Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class fibonacchi
- {
- public static void main(String[] args)
- {
- int fold1 = 1;
- int fold2 = 1;
- int foldNew = fold1 + fold2;
- Scanner s = new Scanner(System.in);
- System.out.println(Integer:");
- int nthPosition = s.nextInt();
- if(nthPosition == 1)
- {
- foldNew = 1;
- }
- else if(nthPosition == 2)
- {
- foldNew = 1;
- }
- else if(nthPosition == 3)
- {
- foldNew = 2;
- }
- else if(nthPosition > 3)
- {
- for(int i = 1; i <= (nthPosition - 3); i++)
- {
- fold2 = fold1;
- fold1 = foldNew;
- foldNew = fold2 + fold1;
- }
- }
- System.out.println(foldNew);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement