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
Give the output of the following code:
String P = "20", Q ="19"; int a = Integer.parseInt(P); int b = Integer.valueOf(Q); System.out.println(a+""+b);What is the method to check whether a character is a letter or digit?
- isDigit(char)
- isLetterOrDigit()
- isLetterOrDigit(char)
- isLETTERorDIGIT(char)
Predict the output of the following code snippet:
char ch='B', char chr=Character.toLowerCase(ch); int n=(int)chr-10; System.out.println((char)n+"\t"+chr);