Answered step by step
Verified Expert Solution
Question
00
1 Approved Answer
Problem 1: [15 marks Convert binary string to decimal with exception (filename: BinaryToDecimalWithException.java) Write a method with the following header to convert a binary string
Problem 1: [15 marks Convert binary string to decimal with exception (filename: BinaryToDecimalWithException.java) Write a method with the following header to convert a binary string to a decimal number. public static int bin2Dec(String binaryString) throws NumberFormatException Implement the bin2Dec method to throw a NumberFormatException if the string is not a binary string. he Naem c pony ie conepond decinal In the main method, ask the user to enter a binary string by using the next0 method, call the method above, and display the correspond decimal value. Your program must catch the NumberFormatException and if the input string is not a binary string, the program should display an appropriate error message. Two sample runs are given below: Enter a binary string: 10011 The corresponding decimal number is 19 Enter a binary number: 12011 ava.lang.NumberFormatException: Binary number format error
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started