蓝桥杯- 基础练习:查找整数

import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int size = scanner.nextInt();
        int ints[] = new int[size];
        for (int i = 0; i < ints.length; i++) {
            ints[i] = scanner.nextInt();
        }
        int findNum = scanner.nextInt();
        for (int i = 0; i < ints.length; i++) {
            if (ints[i] == findNum) {
                System.out.println(i+1);
                break;
            }else if (i+1==ints.length) {
                System.out.println("-1");    //不要忘了输出 -1   ,我纠结了程序半天才发现,
            }
        }
    }
}

 

posted @ 2018-01-14 20:36  Bap  阅读(344)  评论(0编辑  收藏  举报