Prashnikaप्रश्निका
Code
About
‹ Back to the paper

Question 32

1 mark

Computer ScienceISC Computer Science - Competency Focused Practice Questions (CISCE, August 2024)Fill inPrimitive values, Wrapper classes, Types and casting

Fill in the blanks marked ?1?, ?2? ... so that the code works.

Following is a code to convert a String into Double. Fill the missing parts of the code: ____ str =…

Following is a code to convert a String into Double. Fill the missing parts of the code:
____ str = "15.45"; 
double d = ____ (Double.parseDouble(str));

Answer

Answer

Blanks: String; (double)

The first blank is the type of the variable holding the text, so it is String. The second blank is a type cast to double. Double.parseDouble(str) already returns a double, so the cast is harmless:
String str = "15.45";
double d = (double) (Double.parseDouble(str));
d now holds 15.45.