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 :: how to load template file from resource folder in spring boot project 
Java :: issue wsdl call java example 
Java :: inline intent to jump new activity 
Java :: longest palindrome string in java 
Java :: java object array initialization 
Java :: java completablefuture chain 2 operations 
Java :: single line comment in java 
Java :: intellij disable welcome screen 
Java :: what happens if you return only -1 and 1bute not 0 java 
Java :: pioneer meaning 
Java :: find the length of jtextfeild in java 
Java :: python to java code conversion 
Java :: Program to check Vowel or Consonant using Switch Case 
Java :: aaa testing java 
Java :: naming convention for selenium java automation 
Java :: hashmap declare and initialize with values in 1 line java 
Java :: && java 
Java :: swapping techniques using java 
Java :: android array to string 
Java :: how to call a void method from another class in java 
Java :: Calling A Class From Another Class In Java 
Java :: java.lang.ClassNotFoundException: org.postgresql.Driver 
Java :: Access HashMap Elements 
Java :: get image from resourcestream javafx 
Java :: exitonclose swing 
Sql :: reset ids in mysql 
Sql :: alter user mysql native password 
Sql :: mysql_secure_installation 
Sql :: sql server conection string 
Sql :: neo4j display all nodes and relationships 
ADD CONTENT
Topic
Content
Source link
Name
3+8 =