#74 Finding an Element Index in an Array
An int[] nums array is given. Write a method that finds the index of an element in the array:
public class Main {
public static void main(String[] args) {
int[] nums = {10, 20, 30, 40, 50};
int target = 30;
int index = findIndex(nums, target);
System.out.println("Index of " + target + " is: " + index);
}
public static int findIndex(int[] nums, int target) {
...
}
}
Question review
Sign in to start the dialogue
The mentor keeps the context of the current question and your previous messages.
Sign in
Available with Premium
This is just one of the solutions available with Premium. And more:
- 250+ advanced lectures
- 1300+ practice exercises
- 500+ solutions to problems from real interviews
- Personalized Java Hub certificates
- Expanded access to the AI mentor