Friday, February 2, 2018

Fibonacci Series in Java

In this article I would like to share with you a sample program that will ask the user to give a number and then our program will generate the corresponding Fibonacci numbers based on the given number by our user using Java as our programming language.

I am currently accepting programming and web development work kindly contact me in the following email address for further details. Thank you.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.

My telephone number at home here in Bacolod City, Negros Occidental is (034) 4335675.





Sample Program Output



Program Listing

fibonacci.java

import java.util.Scanner;

// fibonacci.java
// Written By Mr. Jake R. Pomperada, MAED-IT
// February 2, 2018   11:09 AM   Friday
// Bacolod City, Negros Occidental Republic of the Philippines
// jakerpomperada@yahoo.com and jakerpomperada@gmail.com

class fibonacci {
public static void main(String[] args)
      {

      int num1=0, a = 0, b = 0, c = 1;;

        Scanner s = new Scanner(System.in);

        System.out.println();
        System.out.println("=== Fibonacci Series in Java === ");
        System.out.println();

         System.out.print("Give a value of n : ");
         num1 = s.nextInt();
          System.out.println();
         System.out.print("Fibonacci Series : ");
        for(int i = 1; i <= num1; i++)
        {
            a = b;
            b = c;
            c = a + b;
            System.out.print(a+" ");
        }

System.out.println("\n");
System.out.println("\t End of Program");
         System.out.println();
}
}










No comments:

Post a Comment