DEV Community

Neelakandan R
Neelakandan R

Posted on

3 2 2 2 2

Decimal to binary,Binary to decimal,Fibonacci series without third variable

binary to decimal==>1001 to 9

package new_practice;
//8421
public class bi_dec_pro {
    static int dec=0;
    public static void main(String[] args)  {
    int no=1001;
    int base=2;
    int power=0;
    int d=finddec(no,base,power);
    System.out.println(d);

}

private static int finddec(int no, int base, int power) {
    while(no>0)
    {
        int rev=no%10;
        int result=rev*find_power(base,power);
        dec=dec+result;
        no=no/10;
        power++;
    }
    return dec;
}

private static int find_power(int base, int power) {
    int result=1;
    while(power>0)
    {
        result=result*base;
        power--;
    }
    return result;
}
}

Enter fullscreen mode Exit fullscreen mode

output:9

**<u>decimal to binary==>9 To 1001</u>**

package new_practice;

public class dec_binary_num {
public static void main(String[] args) {
    int no=9;
    String binary="";
    while(no>0)
    {
        binary=(no%2)+binary;
        no=no/2;
    }
    System.out.println(binary);
}
}

Enter fullscreen mode Exit fullscreen mode

output:1001

Fibonacci series without third variable

package new_practice;

public class fib_no_series {
    public static void main(String[] args) {
        int f = -1;
        int s = 1;
        while ((f + s) < 13) {
            System.out.println(f + s + " ");
            s = f + s;
            f = s - f;
        }
    }
}


Enter fullscreen mode Exit fullscreen mode

0 1 1 2 3 5 8

Heroku

Built for developers, by developers.

Whether you're building a simple prototype or a business-critical product, Heroku's fully-managed platform gives you the simplest path to delivering apps quickly — using the tools and languages you already love!

Learn More

Top comments (0)

Quickstart image

Django MongoDB Backend Quickstart! A Step-by-Step Tutorial

Get up and running with the new Django MongoDB Backend Python library! This tutorial covers creating a Django application, connecting it to MongoDB Atlas, performing CRUD operations, and configuring the Django admin for MongoDB.

Watch full video →

👋 Kindness is contagious

Dive into this insightful write-up, celebrated within the collaborative DEV Community. Developers at any stage are invited to contribute and elevate our shared skills.

A simple "thank you" can boost someone’s spirits—leave your kudos in the comments!

On DEV, exchanging ideas fuels progress and deepens our connections. If this post helped you, a brief note of thanks goes a long way.

Okay