Write the bin2Dec(String binaryString)method to convert a binarystring into a decimal number (yourmethod should return aninteger ). Implement the bin2Decmethod to throw a NumberFormatException if thestring is not a binarystring .
Test yourmethod in aprogram that prompts the user to input a binarystring and uses your bin2Decmethod to print out the decimal equivalent of thatstring . If themethod throws an error, have yourprogram catch it and print "Not a binarystring ." before terminating.
SAMPLE RUN #1: java NumberFormat Interactive Session Standard Input Standard Error (empty) Standard Output Hide InvisiblesHighlight: NoneStandard Input OnlyPrompts OnlyStandard Output w/o PromptsFull Standard OutputAllShow Highlighted Only
Enter·a·binary·string:1011000101