Convert binary to decimal - Java program

Q. Write a program to convert binary number into decimal number.

Answer:

BinaryToDecimal.java

import java.util.Scanner;
class BinaryToDecimalConversion
{
        public static void main(String[] args)
        {
                Scanner in = new Scanner( System.in );
                System.out.println("Enter a binary number: ");

                int  binarynum =in.nextInt();
                int binary=binarynum;
                int decimal = 0;
                int power = 0;

                while(true)
                {
                        if(binary == 0)
                        {
                                break;
                        }
                        else
                        {
                                int temp = binary%10;
                                decimal += temp*Math.pow(2, power);
                                binary = binary/10;
                                power++;
                        }
                }
                System.out.println("Binary="+binarynum+" Decimal="+decimal); ;
        }
}


Output:

binary to decimal