Instead of using
, use
binaryString = scan.next()
. This will get you the necessary binaryString to convert to decimal. It's also unnecessary to have the binary variable. toDecimal is already returning the correct decimal value, so print this out:
System.out.println("The binary number " + binaryString + " corresponds to: " + toDecimal(binaryString));
To fix the check in the while loop, all you need to change it to is this:
while (toDecimal(binaryString) != 0)
I would also change the return type of toDecimal to a either int or long because there's no need to handle binary decimal numbers (floating point number conversion is a whole new can of worms
). This isn't really necessary, but something that I would recommend (choose your variable types to fit the purpose).