题目:
解决方法:
1 //package com.algorithm.java.blueBirdge; 2 3 import java.util.Scanner; 4 5 public class Main { 6 public static void main(String[] args ){ 7 Scanner read =new Scanner(System.in); 8 int n=read.nextInt(); 9 10 int F[]=new int [n]; 11 for(int i=0;i<n;i++){ 12 F[i]=read.nextInt(); 13 } 14 int cheakNumber=read.nextInt(); 15 int j=0; 16 for( ;j<n;j++){ 17 if(cheakNumber==F[j]){ 18 System.out.println(j+1); break; 19 } 20 } 21 if(j==n){ 22 System.out.println("-1"); 23 } 24 25 } 26 27 }
测试结果:
测试成功!