• Latest Code...

    Featured Post

    Implementing Hilt in a Kotlin Android Jetpack Compose Project with MVVM Architecture

     In modern Android development, maintaining a scalable codebase can be challenging, especially when it comes to dependency management. Hilt,...

    Java Tutorials: Calculate fibonacci series in Java


    Calculating fibonacci series in Java

    public class Example1 {

    public static void main(String [] args) {
     fibonacciLoop(5);
    }

     public static void fibonacciLoop(int n){
          if (n == 0) {
               System.out.println("0");
           } else if (n == 1) {
               System.out.println("0, 1, ");
           } else {
               System.out.print("0, 1,  ");
               int a = 0;
               int b = 1;
               for (int i = 1; i < n; i++) {
                   int nextNumber = a + b;
                   System.out.print(nextNumber + ", ");
                   a = b;
                   b = nextNumber;
               }
           }
        }

    Output:

    0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55,


    Contact Form

    Name

    Email *

    Message *