185k views
2 votes
Complete the following Java statement that assigns to the int variable num the decimal equivalent of the given binary string.

Move the code pieces in place to build statement.
num = _____ . ______ (______, ______);
Not all pieces will be used.
______ _____ _____ _____ _____ _____

User Litherum
by
7.8k points

1 Answer

0 votes

Final answer:

To assign the decimal equivalent of a binary string to an integer variable in Java, use the Integer.parseInt method with the binary string and the radix 2 as arguments.

Step-by-step explanation:

The Java statement to assign the decimal equivalent of a binary string to an int variable num involves using the Integer.parseInt method. For example:num = Integer.parseInt(binaryString, 2);This statement uses parseInt from the Integer class and converts a binary number (in string format) to its decimal equivalent. The first argument 'binaryString' should be your binary number as a string, and the second argument '2' indicates that the binary numeral system is being used (base 2).

The code to complete the Java statement that assigns the decimal equivalent of a given binary string to the int variable num is:num = Integer.parseInt(binaryString, 2);This statement makes use of the parseInt method from the Integer class in Java. The parseInt method takes two parameters: the binaryString to convert to an int value, and the base (in this case, 2 for binary). It returns the decimal equivalent of the binary string.

User Amp
by
8.7k points