String in java String comparision in Java Question #22223
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

Choose the Best Option

Click any option to instantly check if you're correct.

  • A 26
  • B 74
  • C 100.0
  • D 2674
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:

  1. String Initialization:

    String A = "26.0";
    String B = "74.0";
    Here, two strings A and B are initialized with the values "26.0" and "74.0" respectively.

  2. Parsing Strings to Double:

    double C = Double.parseDouble(A);
    double D = Double.parseDouble(B);
    The Double.parseDouble(String s) method converts the string argument to a double type. So, C will be 26.0 and D will be 74.0.

  3. Calculating Sum:

    System.out.println((C + D));
    The sum of C and D is calculated. Therefore:
    C + D = 26.0 + 74.0 = 100.0

  4. Printing the Result:

    The result is printed using System.out.println, which will display 100.0.

Conclusion:

The output of the code is: 100.0

No Previous No Next

Share This Question

Challenge a friend or share with your study group.