181k views
3 votes
The 'parseInt' method of the 'Integer' class throws a 'NumberFormatException' when it is passed a String argument that it cannot convert to an int. Given the String variable s (which has already been assigned a value), write the code needed to convert the value in s as ________.

User Ajayc
by
5.6k points

1 Answer

1 vote

Answer:

new BigInteger(s);

See the explanation

Step-by-step explanation:

Since "parseInt" throws a 'NumberFormatException"; the best solution will be to use 'BigInteger'. Since 's' is already assigned a value, we can print it out as:

System.out.println(new BigInteger(s));

The BigInteger class might need to be imported to the class using:

import java.math.BigInteger;