What would it return given a list (alice, bob, charlie, dave) and - ProProfs Discuss
Topics
Products
Follow Us:

What would it return given a list (alice, bob, charlie, dave) and input bob?
(Assume the foreach is in alphabetic order)public int indexOfName(String name, List names) {  int i = 0;  for(String aName : names) {    if (aName.equals(name)) {      return i;    } else {      i++;    }  }    return i;}



A. 2
B. 0
C. 1
D. -1

This question is part of Programmer Questionnaire
Asked by Hiring_test, Last updated: Jan 30, 2020

+ Answer
Request

1 Answer

hiring_test

Hiring_test

Answered May 22, 2018

1
 

Search for Google images
Select a recommended image
Upload from your computer
Search for Google images
Select a recommended image
Upload from your computer
Search for Google images
Select a recommended image
Upload from your computer

Email Sent
We have sent an email to your address "" with instructions to reset your password.