Question:

Multiple choice question (string)

by  |  earlier

0 LIKES UnLike

Which of the following statement checks that the value of 2 Strings, string1 and string2 are the same?

a) if (string1 == string2)

b) if (string1 = string2)

c) if (string1.equals (string2))

d) if (string1.isEqual (string2))

My answer is c)... But a) is also considered correct? ohya, about d)... if it's if(string1.isEqualTo (string2)), is it correct?

 Tags:

   Report

5 ANSWERS


  1. First of all, you need to specify what programming language you are trying to use.

    I know C, and using C, you hafta use a system function called STRCMP to compare two strings. It goes like this:

    if(strcmp(string1, string2) == 1)) {

    }

    1 meaning they are the same, 0 meaning they are not.


  2. Ok. It depends on the language.

    I use JavaSCript and the right syntax I know it's a)

    Then "c)", could be fine if there's a method that compares the content of string1 with the argument passed into this method, in this case string2.

  3. u can use

    if (string1 == string2)

    string1 isEqual:string2

    string1.Equals(string2)


  4. a) is definately the most logical way for varients of the C language ;).

  5. Assuming that this question is about Java and not about JavaScript nor C, nor C++,

    answer a) is true if the two string objects being compared are the same object, that is, they occupy the same space in memory.

    answer c) is true if the two string objects are the same object (as in answer a.) or it is true because the two strings have all of the same characters in them.  Note that this test is case-sensitive.  If you want to compare two strings, without counting differences in case, you would use an expression like the following expression:

    if (string1.equalsIgnoreCase(string2))

Question Stats

Latest activity: earlier.
This question has 5 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.