package fibonacciseries;
import java.util.Scanner;
public class FibonacciSeries {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter the size of the series: ");
int size = input.nextInt();
int first = 0, second = 1, next;
System.out.print(first + " " + second + " ");
for (int i = 3; i <= size; i++) {
next = first + second;
System.out.print(next + " ");
first = second;
second = next;
}
}
}
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