Ask Question
30 March, 17:38

The following is intended to return the location of the first instance of the String the user enters from the keyboard, - 1 if not found.

String names [] = new String[20];

//assume array is initialized

System. out. println ("Enter a name to search for: ");

String lookingFor = scan. nextLine ();

int found = - 1;

for (int i = 0; i < names. length; i++) {

if ( / * Missing Code * / ) {

found = i;

break;

}

}

Which of the following could replace / * Missing Code * / so that it works as intended?

1. lookingFor. equals (names[i])

2.! lookingFor. equals (names[i])

3. lookingFor! = names[i]

4. lookingFor. equals names)

5. lookingFor [i]. equals (names[i])

+1
Answers (1)
  1. 30 March, 18:39
    0
    1. lookingFor. equals (Names[i])

    When comparing Strings, you wanna use. equals () cause String is a 'reference type'. (You'll use = = for primitive types).
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “The following is intended to return the location of the first instance of the String the user enters from the keyboard, - 1 if not found. ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers