Single Choice Moderate

QPredict the output of the following code snippet:

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

ID: #23952 ICSE Computer Application - Class X - 2023 PYQ 99 views
Question Info
#23952Q ID
ModerateDifficulty
ICSE Computer Application - Class X - 2023 PYQTopic

Choose the Best Option

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

  • A 20
  • B 20 22
  • C 2220
  • D 22
Correct Answer

Explanation

20 22

Reason — The values of strings P and Q are converted into integers using the Integer.parseInt() method and stored in int variables a and b, respectively.
When the statement System.out.println(a + " " + b) is executed, first the operation a + " " is performed. Here, int variable a is converted to a string and a space is concatenated to it resulting in "20 ".
After this, the operation "20 " + b is performed resulting in 20 22 which is printed as the output.

Share This Question

Challenge a friend or share with your study group.