分析:
这题似乎没什么好说的,比较简单。注意位置从1开始编号即可。
Java代码实现:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();//数列长度
//定义数组并接收数值
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = scanner.nextInt();
}
int a = scanner.nextInt();
for (int i = 0; i < n; i++) {
if (a == arr[i]) {
System.out.println(i + 1);
break;
} else if(i == n-1){
System.out.println(-1);
}
}
}
}