一、题目链接
http://noi.openjudge.cn/ch0109/01/
二、解题思路
三、实施步骤
四、Java程序
import java.util.Scanner;
public class Main {
public int firstOccur(int[] nums, int target) {
int n = nums.length;
for (int i = 0; i < n; i++) {
if (nums[i] == target) {
return i + 1;
}
}
return -1;
}
public static void main(String[] args) {
Main test = new Main();
Scanner input = new Scanner(System.in);
int n = input.nextInt();
int[] nums = new int[n];
for (int i = 0; i < n; i++) {
nums[i] = input.nextInt();
}
int target = input.nextInt();
System.out.print(test.firstOccur(nums, target));
}
}