Prashnikaप्रश्निका
Code
About
‹ Back to the paper

Question 9

1 mark

Computer ScienceISC Computer Science - Competency Focused Practice Questions (CISCE, August 2024)MCQArrays, Strings

Choose the correct option.

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 );
  • (a)2 234234 234234
  • (b)Error
  • (c)3 234234 468
  • (d)3 468 234234

Answer

Answer

Correct 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".