public class Fibonacci { public static void main(String[] args) { Scanner in = new Scanner(System.in); // Setting up scanner System.out.print("Enter an integer: "); int num = in.nextInt(); in.close(); // Close scanner when done using it long current = 1; long previous = 0; // Add for loop logic here } }
Write a java program called Fibonacci.java that prints the first n numbers of the Fibonacci sequence (starting with 0), where n is an integer entered by the user. Use a for loop. Some of the program has been provided below.
More info about Fibonacci can be found here:
https://www.mathsisfun.com/numbers/fibonacci-sequence.html
https://www.youtube.com/watch?v=wTlw7fNcO-0
import java.util.Scanner;
public class Fibonacci {
public static void main(String[] args) {
Scanner in = new Scanner(System.in); // Setting up scanner
System.out.print("Enter an integer: ");
int num = in.nextInt();
in.close(); // Close scanner when done using it
long current = 1;
long previous = 0;
// Add for loop logic here
}
}
Step by step
Solved in 3 steps with 2 images