Here we are going to write a program on conversion of Binary to Decimal Numbers in Java.

## Binary To Decimal Conversion :

ConvertBinaryToDecimal.java
``````import java.util.Scanner;

public class ConvertBinaryToDecimal {

public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a Binary Number : ");
String input = sc.nextLine();
convertBinaryToDecimal(input);
}

public static int convertBinaryToDecimal(String number) {
int length = number.length() - 1;
int decimal = 0;
if (isBinary(number)) {
char[] digits = number.toCharArray();
for (char digit : digits) {
if (String.valueOf(digit).equals("1")) {
decimal += Math.pow(2, length);
}
--length;
}
System.out.println("The Decimal Number is : " + decimal);
}
return decimal;
}

public static boolean isBinary(String number) {

boolean isBinary = false;

if (number != null && !number.isEmpty()) {
int num = Integer.parseInt(number);
while (num > 0) {
if (num % 10 <= 1) {
isBinary = true;
} else {
isBinary = false;
break;
}
num /= 10;
}
}

return isBinary;
}

}``````

Output :

``````Enter a Binary Number : 1011101
The decimal number is : 93﻿``````
``` Happy Learning 🙂 Related Posts Decimal To Binary Conversion Java Program Java program to find sum of digits Java Program To Count number of words in a String Binary To Hexadecimal Conversion Java Program Decimal To Hex Conversion Java Program Decimal To Octal Conversion Java Program Octal To Decimal Conversion Java Program Binary Search using Java Java Program For Binary Addition Java Program for Check Octal Number Java Program for Reverse Of Number Java Program for Reverse of String Java Program To check a number is prime or not ? Java Program To find A Number is ArmStrong or Not ? Java Program to Find the GCD of Two Numbers ```