➽ Program:-

import java.util.*;

class Main

{

    public static void main(String args[])

    {

        int  number, binary_value, decimal_value = 0, base = 1, rem;

        Scanner s = new Scanner(System.in);

 

        System.out.print("Enter a Binary Number(In 0s and 1s): ");

        number = s.nextInt();

       

        binary_value = number;

 

        while(number > 0)

        {

            rem = number % 10;

            decimal_value += rem * base;

            number = number / 10 ;

            base = base * 2;

        }

       

        System.out.print("Decimal Equivalent of "+binary_value+" is "+decimal_value);

    }

}

➽ Output:-

Enter a Binary Number(In 0s and 1s): 10111001
Decimal Equivalent of 10111001 is 185