KnowledgeBoat Logo

Output Questions for Class 10 ICSE Computer Applications

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);

Java

Java Library Classes

ICSE

21 Likes

Answer

Output of the above code is:

Result 1 = 26100200
Result 2 = 126

Working

  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.

Answered By

12 Likes