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     } }

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter7: Characters, Strings, And The Stringbuilder
Section: Chapter Questions
Problem 9PE
icon
Related questions
Question

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
    }
}

Expert Solution
steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Top down approach design
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT