class ArrayDemo4 { public static void main(String[] args) { int[] arr = {18,16,14,25,8,11}; int index = getIndex(arr,8); System.out.println("index = "+index); } public static int getIndex(int[] arr,int key) { for (int x = 0;x <arr.length ;x++ ) { if (arr[x] == key) return x; } return -1; } } |