. Create a program that will display a Fibonacci series of numbers. The program should ask the user to enter the size of the series and will automatically show the Fibonacci series from 0 to the given size.
Sun Dec 08 2024 11:39:50 GMT+0000 (Coordinated Universal Time)
Saved by
@John_Almer
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;
}
}
}
content_copyCOPY
Comments