Java, how to compare Strings with String Arrays

后端 未结 6 1949
耶瑟儿~
耶瑟儿~ 2020-12-15 06:07

I have been searching here for some time but haven\'t been able to find the answer to it.

I am basically required to use an array for this assignment from college. A

6条回答
  •  春和景丽
    2020-12-15 06:55

    Iterate over the codes array using a loop, asking for each of the elements if it's equals() to usercode. If one element is equal, you can stop and handle that case. If none of the elements is equal to usercode, then do the appropriate to handle that case. In pseudocode:

    found = false
    foreach element in array:
      if element.equals(usercode):
        found = true
        break
    
    if found:
      print "I found it!"
    else:
      print "I didn't find it"
    

提交回复
热议问题