Quick actions

cmd+k|ctrl+k

Navigation

Languages

nth Fibonacci

Snippet info

Language

Java

Visibility

public

Author

pranavchaitu676

Created

2024-01-28T17:24:13.872303Z

Updated

2024-01-28T17:24:37.226953Z

import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		System.out.println("Enter the nth position you want");
		int x = in.nextInt();
		int a = 0;
		int b = 1;
		int count = 2;
		while(count <= x){
			int temp = b;
			b += a;
			a = temp;
			count++;
		}
		System.out.println(b);
	}
}


INFO