ICSE Class 10 Computer Applications Question 9 of 16

Using Library Classes — Question 11

Back to all questions
11
Question

Question 11

Find the error :

double n2 = Double.parseDouble("2"); 
double n3 = Double.parseDouble("OCA"); 
System.out.println(n2 + " " + n3);
Answer

double n3 = Double.parseDouble("OCA"); statement will generate NumberFormatException at the time of conversion of String argument "OCA" to double data type. The exception is raised because "OCA" is not a valid string representation of a numeric value, therefore it cannot be converted to Integer object.