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

Question 7

1 mark

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

Choose the correct option.

String Description StringA Password entered by the user StringB Password stored by the system…

StringDescription
StringAPassword entered by the user
StringBPassword stored by the system
Passwords are stored as two Strings-one is the user entered password saved in StringA, the other is a password stored by the system in StringB. If StringA must be checked with StringB, for validity, which one of the following String functions are needed to be used?
  • (a)charAt( )
  • (b)equals( )
  • (c)equalsIgnoreCase( )
  • (d)startsWith( )

Answer

Answer

Correct option: b

Answer: (b) equals( ). A password check needs an exact, case-sensitive comparison, which String's equals( ) method gives. equalsIgnoreCase( ) would wrongly accept passwords differing only in case, and charAt( )/startsWith( ) do not compare the whole string.