Jigar Patel Jigar Patel - 1 year ago 69
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?

Answer Source

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';
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download