KnowledgeBoat Logo

Output Questions for Class 10 ICSE Computer Applications

Give the output of the following code:


String P = "20", Q ="19";
int a = Integer.parseInt(P);
int b = Integer.valueOf(Q);
System.out.println(a+""+b);

Java

Java Library Classes

ICSE

34 Likes

Answer

Output of the above code is:

2019

Working

Both Integer.parseInt() and Integer.valueOf() methods convert a string into integer. Integer.parseInt() returns an int value that gets assigned to a. Integer.valueOf() returns an Integer object (i.e. the wrapper class of int). Due to auto-boxing, Integer object is converted to int and gets assigned to b. So a becomes 20 and b becomes 19. 2019 is printed as the output.

Answered By

18 Likes