Single Choice
Easy
QGive the output of the following code:
String A = "26.0";
String B = "74.0";
double C = Double.parseDouble(A);
double D = Double.parseDouble(B);
System.out.println((C + D));
ID: #22223
String comparision in Java
117 views
Question Info
#22223Q ID
EasyDifficulty
String comparision in JavaTopic
Your Answer
Choose the Best Option
Click any option to instantly check if you're correct.
Correct Answer
Explanation
Let's analyze the given code step by step to determine its output.
Code:
String A = "26.0";
String B = "74.0";
double C = Double.parseDouble(A);
double D = Double.parseDouble(B);
System.out.println((C + D));
Explanation:
-
String Initialization:
String A = "26.0";String B = "74.0";
Here, two stringsAandBare initialized with the values "26.0" and "74.0" respectively. -
Parsing Strings to Double:
double C = Double.parseDouble(A);double D = Double.parseDouble(B);
TheDouble.parseDouble(String s)method converts the string argument to adoubletype. So,Cwill be 26.0 andDwill be 74.0. -
Calculating Sum:
System.out.println((C + D));
The sum ofCandDis calculated. Therefore:C + D = 26.0 + 74.0 = 100.0 -
Printing the Result:
The result is printed using
System.out.println, which will display100.0.
Conclusion:
The output of the code is: 100.0
Continue Practice
Share
Share This Question
Challenge a friend or share with your study group.