id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

srp4379@lausd.net > searchIndex
prev  |  next  |  chance

public int searchIndex(int val, int[] list)

Given a list of integers and an integer,
if the integer (val) is in the list, return its index, i.e. its position in the list.
Otherwise return -1.

Note: You can solve this using a for-each loop.


searchIndex(4, [2, 3, 4, 5, 6]) → 2
searchIndex(8, [2, 3, 4, 5, 6]) → -1
searchIndex(4, [12, 13, 14, 15, 16]) → -1

...Save, Compile, Run (ctrl-enter)

public int searchIndex(int val, int[] list) { }

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Java Help

Misc Code Practice

Difficulty: 100

Copyright Nick Parlante 2017 - privacy