The method header is as follows: public static int binaryToDecimal(String binaryString)
The program should prompt the user to enter a binary string and display the corresponding decimal integer value.
This is a sample of what the program should do:
Enter a binary number string: 1111111111
The decimal value is 1023
Ok I am not sure what to do next, I am thinking that I should try to do a for loop next but its just not working out in my head.
import java.util.Scanner;
public class Exercise09_08 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
// Prompt the user to enter a string
System.out.print("Enter a binary number string: ");
String s = input.nextLine();
System.out.println("The decimal value is " + binaryToDecimal(s));
}
public static int binaryToDecimal(String binaryString) {
}
}
}
Thanks

New Topic/Question
Reply



MultiQuote




|