‹ Back to the paper
For the following code snippet choose the correct output: int x = 234; String str =…
For the following code snippet choose the correct output:
int x = 234;
String str = String.valueOf(x) ;
System.out.println(str.length( ));
System.out.println( x + x );
System.out.println( str + str );- a2 234234 234234
- bError
- c3 234234 468
- d3 468 234234
Answer
Answer
AICorrect option: d
Answer: (d) 3
468
234234.
String.valueOf(234) gives "234", whose length( ) is 3. x + x adds the two int values numerically, giving 468. str + str concatenates the two Strings, giving "234234".
From ISC Computer Science - Competency Focused Practice Questions (CISCE, August 2024), question 9.