Hi guys.got some problem in this program.Was suppose to write a program to get a binary string and display its value. Need to have 3 methods.
-Receive string which represents the value
-Converts the binary value to decimal
-Receive string as parameter
-Return true if string contains 0s and 1s,false otherwise
-Read input using scanner class
-Call validateInput() method to check whether inputted value is binary value,display error message and repeat input process
-call binaryToDecimal() method to get its converted decimal value and display it
had some problem in the validateInput() part. not sure is it correct
Or use Integer.valueOf(String, 16) and catch the exception.
I have edited your post to UseCodeTags; please do that in the future when posting code of an length. Otherwise it's unnecessarily hard to read the code, making it less likely that people will bother to do so.
Ernie Mcracken wrote:So you need to read your string using your Scanner then call the validateString() method
If you are going to have this in the same class as your Main then you'll need to make the validateString() method static.
Thanks Ernie again almost there,but now the problem is when i try to type "exit",the program doesn't exit.I need to display a message stating that "Please enter a proper binary number" when the validation returns false and allows the user to type another input.Appreciate the help as i quite new in programming.