1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
olasank [31]
3 years ago
8

Fibonacci sequence has many applications in Computer Science. Write a program to generate Fibonacci numbers as many as desired.

After the construction, you can print the sum value of the sequence. The example is below and user input is in boldface. Enter the number of terms: 6 First 6 terms of Fibonacci numbers are: 0 1 1 2 3 5 The sum value of the above sequence is: 12 Fibonacci sequence: First few numbers are 0, 1, 1, 2, 3, 5, 8 etc., except first two terms in sequence every other term is the sum of two previous terms, For example 8 = 3 + 5 (addition of 3, 5).
Computers and Technology
1 answer:
choli [55]3 years ago
5 0
<h2>Answer:</h2>

//import Scanner class

import java.util.Scanner;

//Class header definition

public class Fibonacci_Series {

   //main method    

   public static void main(String[] args) {

       //create an object of the Scanner class to allow for user's input

       Scanner input = new Scanner(System.in);

       //Ask the user to enter the number of terms

       System.out.println("Enter the number of terms");

       //Assign user input to a variable

       int nTerms = input.nextInt();

       //Declare and initialize to zero a variable sum to hold the sum of the series.

       int sum = 0;

       //Show message

       System.out.println("First " + nTerms + " terms of Fibonacci numbers are");

       

       //Create a for loop that cycles as many times as the number of terms entered by user

       //At every term (cycle), call the fibonacci method on the term.

       //And add the number to the sum variable

       for (int i = 1; i <= nTerms; i++){

         System.out.println(fibo(i));

         sum = sum + fibo(i);

       }   //End of for loop

       //show message

       System.out.println("The sum of the above sequence is ");        

       //Display the sum of the fibonacci series

       System.out.println(sum);

   }    //End of main method

   

   //Method fibo to return the nth term of the fibonacci series

   public static int fibo(int n){

       //if n = 1,  

       // the fibonacci number is 0

       if (n <= 1){

           return 0;

       }

       //if n = 2,  

       // the fibonacci number is 1

       else if(n == 2){

           return 1;

       }

       //if n > 2, fibonacci number is the sum of the previous two numbers

       else {

           return fibo(n-1) + fibo(n-2);

       }

   }   // End of method fibo

}    // End of class declaration

<h2>Sample Output:</h2>

<em>Enter the number of terms</em>

>> 6

<em>First 6 terms of Fibonacci numbers are</em>

0

1

1

2

3

5

<em>The sum of the above sequence is  </em>

12

<h2 /><h2 /><h2>Explanation:</h2>

The above code has been written in Java.

The code contains comments explaining important parts of the code. Kindly go through the comments for better readability and understanding.

The source code file of this question has been attached to this response. Please download it and go through it for better formatting.

Download java
You might be interested in
Which of the following is a Web browser? Exit Test A Windows B Comcast High-Speed C Microsoft Internet Explorer D Modem
yulyashka [42]
C. Internet explorer
Hope this helps :) please thank!
8 0
3 years ago
In computers, when the print command is executed, a cable carries this signal from the computer to the printer. In comparing a c
storchak [24]

Answer:

a) axon

Explanation:

In computers, when the print command is executed, a cable carries this signal from the computer to the printer. In comparing a computer to a neuron, the cable that carries the signal between the computer and the printer would be equivalent to an axon which is used to communicate messages to external cells.

Dendrites is not relevant because it represents the termination components of axon.

8 0
3 years ago
For an IP or device that is in the local network, it's a very straight forward cache table lookup for its MAC address. How does
astra-53 [7]
It doesn't really. The address is recognized as off the local network, so at the IP layer the packet is sent to the router, whose address is in the ARP table. As the packet travels to different hops, the MAC address is updated to the next hop.
8 0
4 years ago
Paul has been working long hours. He is tired and distracted by family issues, so he has not been doing record updates regularly
mina [271]

Answer:

Accidental data loss

Explanation:

Accidental data loss -

It refers to the removal or loss of certain data or information from the computer , due to some accident , is referred to as accidental data loss .

The loss of data can be due to some malicious intruders , or can be due to the fault of the user .

The information can be lost due to sudden power cut , natural calamities like fires , flood earthquake etc. , problem in hard disk etc.

Hence , from the given scenario of the question ,

The correct option is accidental data loss.

4 0
3 years ago
Traffic shaping reduces traffic by ________. preventing certain undesirable traffic from entering the network limiting the amoun
Lera25 [3.4K]

Answer:

Explanation:

Traffic Shaping is a technique for managing congestion on a network by delaying the flow of less important/desired packets on the network so more valuable/desirables ones are able to pass. Traffic shaping reduces traffic by preventing certain undesirable traffic from entering the network as well as limiting the amount of certain undesirable traffic entering the network.

5 0
3 years ago
Other questions:
  • What does this say:<br> √ans
    6·2 answers
  • Rapid development programming languages eliminate the possibility of having bugs in code. True or False
    8·1 answer
  • (Package Inheritance Hierarchy) Package-delivery services, such as FedEx®, DHL® and UPS®, offer a number of different shipping o
    10·1 answer
  • Write a try block in which you prompt the user for an integer and display the name in the requested position in the names array.
    11·1 answer
  • In a _______ format, the date line and the signature block are centered.
    6·1 answer
  • T.L.E
    6·1 answer
  • Public class Dog
    7·1 answer
  • When the narrator of "EPIC 2015" describes the year 2015 as the "worst of
    6·1 answer
  • patty works at Mcdonald's as a chef. it is her job to make hamburgers as each order arrives on her computer screen. one day patt
    11·2 answers
  • What is a good indicator that someone on social media is not who he or she claims to be?
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!