Computer Applications
Which of the following is the correct method to convert a String to a double in Java?
Answer
Double.parseDouble(String)
Reason — Double.parseDouble(String) method converts a String representation of a number into a primitive double.
Analysing other options:
String.toDouble()— Incorrect. This method does not exist in Java.Double.parseDouble()— Incorrect. This is syntactically incomplete, as it requires aStringargument.Double.valueOf(String)— Incorrect. This converts theStringto aDoubleobject, not a primitivedouble.
Related Questions
Assertion (A): Integer class can be used in the program without calling a package.
Reason (R): It belongs to the default package java.lang.
- Both Assertion (A) and Reason (R) are true and Reason (R) is a correct explanation of Assertion (A)
- Both Assertion (A) and Reason (R) are true and Reason (R) is not a correct explanation of Assertion(A)
- Assertion (A) is true and Reason (R) is false
- Assertion (A) is false and Reason (R) is true
The method to convert a lowercase character to uppercase is:
- String.toUpperCase( )
- Character.isUppercase( char )
- Character.toUpperCase( char )
- toUpperCase ( )
State the data type and value of res after the following is executed:
char ch = '9'; res= Character.isDigit(ch);