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

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

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

Post 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; }
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply