Page 1 of 1

Hi, i cant seem to find whats wrong with my code. If i could get some help please * @param list * @param target * @retur

Posted: Thu May 05, 2022 12:54 pm
by answerhappygod
Hi, i cant seem to find whats wrong with my code. If i could get
some help please * @param list * @param target * @return the SECOND
index at which target exists in the list passed. * return -1 if
list is null or target doesn't exist TWICE in the list. */ public
static int secondIndexOf(ArrayList list, int target) {
int count = 0;
int idx = 0;
if(list == null) {
return -1; }
for(int i = 0; i < list.size(); i++) {
if(list.get(i) == target) {
count++; } }'
if(count == 2) {
return list.indexOf(target); }
return -1; }