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

Respuesta :

Answer:

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

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