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);
- 2019
- 39
- 20
- 19
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.
Related Questions
In …………… search, the algorithm uses the middle value of the array for the search operation.
- binary
- linear
- bubble
- selection
A single dimensional array contains N elements. What will be the last subscript?
- N
- N - 1
- N - 2
- N + 1
What will be the output of following code?
String c = "Hello i love java"; boolean var; var = c.startsWith("hello"); System.out.println(var);- true
- false
- 0
- 1
A string function which removes the blank spaces provided in the prefix and suffix of a string.
- String.trim()
- String.ltrim()
- String.rtrim
- String.strim