Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- public class Main {
- public static void main(String[] args) {
- int[] numberArray = {3, 5, 7, 12, 6};
- int target = 12;
- int indexNumber = GetIndex(numberArray, target);
- System.out.println("Index found was: " + indexNumber);
- }
- public static int GetIndex(int[] nums, int target) {
- for(int i=0; i<nums.length; i++) {
- if(nums[i] == target) {
- return i;
- }
- }
- return -1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement