Computer Applications

Identify 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);
  1. 2019
  2. 39
  3. 20
  4. 19

Java Library Classes

5 Likes

Answer

2019

Reason — In the given code, first strings P and Q are converted to their corresponding integer values. So a becomes 20 and b is 19. In the statement System.out.println(a + "" + b); the expression a + "" performs string concatenation as one of the operands of + operator is a string (empty string ""). As a result, the integer value a is converted to a string. It is then concatenated with variable b to give the output as 2019.

Answered By

3 Likes


Related Questions