Jigar Patel Jigar Patel - 1 month ago 4x
Java Question

What would be the value of variable after executing the following statement

I'm lil bit confused about this question which i found while doing 1 vasic java quiz

question is:
What would be the value of variable c after executing

int c = Integer.parseInt("a");

I think answer would be 97, which is ASCII value of "a"

am I correct?


It throws a NumberFormatException. From the Javadoc on Integer.parseInt(String s):

NumberFormatException - if the String does not contain a parsable int.

Retrieving the ASCII value of a character is done like this:

char ch='a';