Computer Applications
Predict 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);
- 20
- 20 22
- 2220
- 22
Java Library Classes
ICSE 2023
32 Likes
Answer
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.
Answered By
16 Likes
Related Questions
Write a method prototype name check() which takes an integer argument and returns a char:
- char check()
- void check (int x)
- check (int x)
- char check (int x)
The number of values that a method can return is:
- 1
- 2
- 3
- 4
The String class method to join two strings is:
- concat(String)
- <string>.joint(string)
- concat(char)
- Concat()
The output of the function "COMPOSITION".substring(3, 6):
- POSI
- POS
- MPO
- MPOS