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 :: square root of a number in java without sqrt 
Java :: cannot find symbol variable log 
Java :: concat result of List to one text java 
Java :: java find all of letter in string 
Java :: get the max value from arrayList java and save it in int 
Java :: java declare array 
Java :: How to perform quick sort, in Java? 
Java :: java button size 
Java :: Java Create a ConcurrentHashMap 
Java :: how to initialize array in java 
Java :: how to check the current user in firebase android 
Java :: map string string to java object 
Java :: intent pick action video android 
Java :: numbers of digits java 
Java :: Spring boot enable openapi swagger accessed 
Java :: arrays.aslist 
Java :: open website from android activity 
Java :: intellij 
Java :: iterate thrpugh hasmap 
Java :: java stream get all max values 
Java :: flutter java.lang.RuntimeException: Unable to instantiate activity ComponentInfo 
Java :: get the length of an array java 
Java :: bean factory vs application context 
Java :: android iinput edit text password icon change 
Java :: start async task android 
Java :: how to find selenium webelement java 
Java :: java stream loop 
Java :: largest rectangle in histogram leetcode 
Java :: convert a int to string in java 
Java :: print string in java 
ADD CONTENT
Topic
Content
Source link
Name
2+9 =