import java.util.Scanner;
public class BinaryToDecimal {
public static void main(String[] args) {
System.out.println("Enter a binary number: ");
Scanner scanStr = new Scanner(System.in);
int decimalNum = 0;
if(scanStr.hasNext())
{
try
{
decimalNum = Integer.parseInt(scanStr.next(),2);
System.out.println("Binary number in decimal is: "+decimalNum);
}
catch(NumberFormatException nfe)
{
System.out.println("The number is not a binary number.");
}
}
}
}
parking panic
ReplyDeleteclickplay time 5