Home / Questions / Give the output of the following code: String A ="26", B="100"; String D=A+B+"200"; int x= Integer.parseInt(A); int y = Integer.parseInt(B); int d = x+y; System.out.println("Result 1 = " + D); System.out.println("Result 2 = " + d);
Explanatory Question

Give the output of the following code:

String A ="26", B="100";
String D=A+B+"200";
int x= Integer.parseInt(A);
int y = Integer.parseInt(B);
int d = x+y;
System.out.println("Result 1 = " + D);
System.out.println("Result 2 = " + d);

👁 77 Views
📘 Detailed Answer
🕒 Easy to Read
Read the answer carefully and go through the related questions on the right side to improve your understanding of this topic.

Answer with Explanation

Output of the above code is:

Result 1 = 26100200
Result 2 = 126
Explanation
  1. As A and B are strings so String D=A+B+"200"; joins A, B and "200" storing the string "26100200" in D.
  2. Integer.parseInt() converts strings A and B into their respective numeric values. Thus, x becomes 26 and y becomes 100.
  3. As Java is case-sensitive so D and d are treated as two different variables.
  4. Sum of x and y is assigned to d. Thus, d gets a value of 126.