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
Andrew [12]
3 years ago
13

The Fibonacci numbers are a sequence of integers in which the first two elements are 1, and each following element is the sum of

the two preceding elements. The first 12 Fibonacci numbers are: 1 1 2 3 5 8 13 21 34 55 89 144 Write a piece of code that uses a for loop to compute and print the first 12 Fibonacci numbers. (You may include other code, such as declaring variables before the loop, if you like.)
Computers and Technology
1 answer:
ioda3 years ago
4 0

Answer:

// program in java to print 12 fibonacci terms

// package

import java.util.*;

// class definition

class Main

{

   // main method of the class

public static void main (String[] args) throws java.lang.Exception

{

   try{

     

      // variables

      int no_of_term=12, f_term = 1, s_term = 1, n_term = 0;

      System.out.print("First 12 term of Fibonacci Series:");

      // print 12 terms of the Series

       for (int x = 1; x<= no_of_term; x++)

           {

       // Prints the first two terms.

            if(x <=2 )

            System.out.print(1+" ");

            else

            {

               // find the next term

                n_term = f_term + s_term;

                // update the last two terms

                f_term = s_term;

                s_term = n_term;

                // print the next term

              System.out.print(n_term+" ");

            }

           }

     

     

   }catch(Exception ex){

       return;}

}

}

Explanation:

Declare and initialize no_of_term=12,f_term=1,s_term=1 and n_term=0.Run a loop  for 12 times, for first term print 1 and then next term will be calculated as  sum of previous two term of Series.Then update previous two term.This will  continue for 12 time and print the terms of Fibonacci Series.

Output:

First 12 term of Fibonacci Series:1 1 2 3 5 8 13 21 34 55 89 144

You might be interested in
Making phone calls with a public box
AfilCa [17]

Answer:

ja ok it is so eassssy.........................

8 0
3 years ago
What function would be used if you want to compare all other rows with the first row?
tester [92]

Answer:

B

Explanation:

the person at the very top said so :)

6 0
3 years ago
What is the most important thing you should avoid when you store files and folders?
iVinArrow [24]
Getting hacked by someone
4 0
3 years ago
Type of malware that is spread when you distribute
vladimir1956 [14]
Trojans, normal viruses, etc. Anything can and could hop on to the files you send depending on the websites and if you don't have a firewall.
3 0
4 years ago
The Grow Font button appears on the ____ tab.
Leni [432]
The Grow Font button appears on the home tab.
5 0
4 years ago
Other questions:
  • Sean is white hat hacker, who is demonstrating a network level session hijack attacks and as part of it, he has injected malicio
    6·1 answer
  • Design and implement your own simple class to represent any household item of your choice (toaster, fan, hair dryer, piano ...)
    11·1 answer
  • Help please fast
    6·2 answers
  • Please help!!
    8·1 answer
  • Which of the following ensures that dropped packets are resent?
    9·1 answer
  • Which processor family is most likely found on recent gaming laptops (Gaming laptops require a lot of computational power)?
    11·1 answer
  • What best describes "broadband access"?
    13·1 answer
  • When you expect a reader of your message to be uninterested, unwilling, displeased, or hostile, you should Group of answer choic
    15·1 answer
  • Identify 5 products/services needed by the people in our current situation.<br>​
    6·1 answer
  • Innovation made from establishment of abucas to the present 5th
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!