class ArrayDemo5{
public static void main(String[] args){
int[] arr = {330,250,888,25,15} ;
int index = getIndex(arr,2500) ;
System.out.println("该元素在数组中第一次出现的索引值是:"+index);
int index2 = getIndex2(arr,150) ;
System.out.println("该元素在数组中第一次出现的索引值是:"+index2);
}
public static int getIndex(int[] arr,int value) {
for(int x = 0 ; x < arr.length ; x ++){
if(arr[x] ==value){
return x ;
}
}
return -1 ;
}
public static int getIndex2(int[] arr,int value) {
int index = -1 ;
for(int x = 0 ; x < arr.length ; x ++){
if(arr[x]==value){
index = x ;
}
}
return index;
}
}
转载请注明原文地址:https://blackberry.8miu.com/read-33679.html