In this page you see a java program to convert binary numbers to decimal numbers. When you run this program,
This program take binary number as input from user and converts it to decimal number. And show output after compile program on the screen.
Binary to Decimal Program Code
package com.androidpro.in;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;
public class Main {
Scanner scan;
int num;
void getVal() {
System.out.println("Binary to
Decimal");
scan = new Scanner(System.in);
System.out.println("\nEnter the number
:");
num = Integer.parseInt(scan.nextLine(), 2);
}
void convert() {
String decimal = Integer.toString(num);
System.out.println("Decimal
Value is : " + decimal);
}
}
class MainClass {
public static void main(String args[])
{
Main obj = new Main();
obj.getVal();
obj.convert();
}
}
Output
Binary to Decimal
Enter the number :
00011
Decimal Value is : 3
Process finished with exit code 0