Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

fibonacci in java

// Java program for the above approach
  // divyaraj
class GFG {
  
    // Function to print N Fibonacci Number
    static void Fibonacci(int N)
    {
        int num1 = 0, num2 = 1;
  
        int counter = 0;
  
        // Iterate till counter is N
        while (counter < N) {
  
            // Print the number
            System.out.print(num1 + " ");
  
            // Swap
            int num3 = num2 + num1;
            num1 = num2;
            num2 = num3;
            counter = counter + 1;
        }
    }
  
    // Driver Code
    public static void main(String args[])
    {
        // Given Number N
        int N = 10;
  
        // Function Call
        Fibonacci(N);
    }
}
Comment

fibonacci number in java

// Java program for the above approach
  // divyaraj
class GFG {
  
    // Function to print N Fibonacci Number
    static void Fibonacci(int N)
    {
        int num1 = 0, num2 = 1;
  
        int counter = 0;
  
        // Iterate till counter is N
        while (counter < N) {
  
            // Print the number
            System.out.print(num1 + " ");
  
            // Swap
            int num3 = num2 + num1;
            num1 = num2;
            num2 = num3;
            counter = counter + 1;
        }
    }
  
    // Driver Code
    public static void main(String args[])
    {
        // Given Number N
        int N = 10;
  
        // Function Call
        Fibonacci(N);
    }
}
Comment

Fibonacci Series in Java

//Iterative Fibonacci series program in Java

class Fibonacci{  
public static void main(String args[])  
{   
//Considering the first two numbers as 0 and 1 
 int num1=0,num2=1,num3,i,count=10;  
//Count=10 means that only the first 10 fibonacci numbers will be displayed  
 System.out.print(num1+" "+num2);
//printing 0 and 1    
 for(i=2;i<count;++i)  
//looping is initiated from 2 as 0 and 1 are already printed  
 {    
  num3=num1+num2;    
  System.out.print(" "+num3);    
  num1=num2;    
  num2=num3;    
 }    
}}  
Comment

PREVIOUS NEXT
Code Example
Java :: hanoi tower java 
Java :: how to loop through a 2d array java 
Java :: how to destroy activity in android 
Java :: worldedit set random blocks 
Java :: change color of action bar android studio 
Java :: android studio textbox change text 
Java :: android studio portrait modeeee 
Java :: for each java 
Java :: clear array java 
Java :: loop list java 
Java :: java while schleife 
Java :: java infinitew recursion 
Java :: java or symbol 
Java :: java create image 
Java :: play sound in java 
Java :: java expressions 
Java :: language of minecraft 
Java :: Error: Could not find or load main class -Djava.library.path=.home.hdoop.hadoop-3.3.0.lib.native 
Java :: java random primary key 
Java :: boolean print condition java 
Java :: java loop through object 
Java :: jbutton set on action 
Java :: write a name and convert it to an array 
Java :: runnable interface in java 
Java :: close a popup selenium python 
Java :: Android dark theme programmatically 
Java :: split string 2 characters java 
Java :: char to int 
Java :: convert array of int to arraylist java 
Java :: java camel case 
ADD CONTENT
Topic
Content
Source link
Name
4+5 =