How to do Fibonacci Sequence in Java Tutorial using NetBeans IDE

0
28

This tutorial is all about How to do Fibonacci Sequence in Java Tutorial using NetBeans IDE. In this tutorial you will learn How to use Fibonacci Sequence in Java Tutorial. Fibonacci is a set of numbers that starts with a one or a zero, followed by a one, and proceeds based on the rule that each number (called a Fibonacci number) is equal to the sum of the preceding two numbers. If the Fibonacci sequence is denotedÂ F(n), whereÂ nÂ is the first term in the sequence, the following equation obtains forÂ nÂ = 0, where the first two terms are defined as 0 and 1 by convention. This tutorial uses some package called Scanner, follow all the steps below to complete this tutorial.

How to do Fibonacci Sequence in Java Tutorial using NetBeans IDE steps

Â

The first step is to, create your project by clicking file at the top of your project and then click new project, you can name your project whatever you want. After that you need to create you class by right clicking the Source Packages and then click the New â€“ Java Class

After that you need to import these packages

import java.util.Scanner;

copy paste the code below:

int k, a = 1, b =1;

Scanner scanner = new Scanner(System.in);

k =0;

System.out.println(“Enter a number: “);

int number = scanner. nextInt ();

System.out.print(“1 1 “);

while(k<=number) {

k = a+ b;

if(k>=number)

break;

System.out.print(k + ” “);

a = b;

b = k;

} JOptionPane.showMessageDialog(null, e);

}

[ /java]

Then youâ€™re done. Run your project and see if it works.

For questions or any other concerns or thesis/capstone creation with documentation, you can contact me through the following:

E-Mail: [email protected]

Contact No.: +639098911050

Ryan A. Salem

BSIT Graduate, soon to be MIT.

Java Developer / System Developer

Related topic(s) that you make like: