求数组中元素的下标,若元素不存在则输出-1
public class Practice6 {
public static int index (int[] array,int n) {
for(int i=0;i<5;i++) {
if(array[i]==5) {
return i;
}
}
return -1;
}
public static void main (String[] args){
int a;
int[] array={6,7,4,9,5};
int b;
b=index(array,5);
System.out.printf("5的下标是%d%n",b);
}
}