import java.util.Scanner; //To calculate Fibonacci Series up to n numbers. public class Main{ public static void main(String[] args) { Scanner in = new Scanner(System.in); //input System.out.print("Enter Your Number :"); int n = in.nextInt(); // 0 1 1 2 3 5 8 13 int a = 0; int b = 1; int count = 2; while(count<n){ int temp = b; b = a+b; a = temp; count++; } System.out.println(b); } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter