import java.util.Scanner;
class Demo {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int[] arr = {1,2,4,3,5,6};
int d = sc.nextInt();
int index = getIndex(arr,d);
System.out.println(index);
}
public static int getIndex(int[] arr,int value){
for (int i = 0 ;i < arr.length ;i++ ) {
if (arr[i] == value) {
return i;
}
}
return 0;
}
}
这是一段根据元素查找角标的代码,理解的晕晕乎乎的,尤其是getIndex这段方法,传的两个参数都是什么意思?哪位大神能帮忙全面解释解释
|
|