76.4k views
5 votes
What does the following statement do if userNumber has an integer value of 14 and userEntry has a string value of “two”? userNumber = Integer.parseInt(userEntry); a. Throws an exception b. Converts “two” to “2” and stores it in userEntry c. Converts “two” to 2 and stores it in userNumber d. Stores a null value in userNumber

1 Answer

1 vote

Answer:

The correct answer for the given question is option(A) i.e Throws an exception .

Step-by-step explanation:

following are the code in java language

public class Main

{

public static void main (String[]args)

{

int userNumber =14;

String userEntry="two";

userNumber= Integer.parseInt(userEntry);

System.out.println(userNumber);

}

}

The main class throws an EXCEPTION java.lang.NumberFormatException

because we cannot convert the string userEntry into integer.

output

Exception in thread java.lang.NumberFormatException

User PJR
by
6.1k points