Java program to find fibonacci fromuser input


Program
import java.util.*; public class Fibonacci { public static void main(String[] args) { Scanner s=new Scanner(System.in); System.out.println("Enter the number of term "); int n = s.nextInt(); int t1 = 0, t2 = 1;; System.out.print("Fibonacci of "+n+" term is "); for (int i = 1; i <= n; ++i) { System.out.print(t1 + " , "); int sum = t1 + t2; t1 = t2; t2 = sum; } } }
Input
Output