Menu Close

Conversion from binary to decimal in Java …ftc

Java Program to convert from binary to decimal number.

Input:
BINARY = 0010

Output:
DECIMAL = 2
import java.io.*;
import java.util.*;
public class temp{
  public static void main(String[] args){ 
    Scanner scan = new Scanner(System.in);
    System.out.print("Binary: ");
    String bin = scan.nextLine();
    
    System.out.println("Decimal: "+Integer.parseInt(bin,2));		
	}
}

INPUT_1:
Binary:  1101

OUTPUT:
Decimal:  13


INPUT_2:
Binary:  111

OUTPUT:
Decimal:  7


INPUT_3:
Binary:  001

OUTPUT:
Decimal:  1


INPUT_4:
Binary:  1111

OUTPUT:
Decimal:  15


INPUT_5:
Binary:  1110
OUTPUT:

Decimal:  14


ILLUSTRATION

Executed using Javac on linux terminal