日期:2014-05-20 浏览次数:20691 次
int[] arr = {1,2,3,4,5};
int num = 6;
int count = 0;
for(int i=0;i<arr.length;i++){
if(arr[i]==num){
System.out.println(i);
}else{
count++;
}
}
if(count==5){
System.out.println("-1");
}
public static void main(String[] args) throws Exception, IOException {
int[] arr = {1,2,3,4,5};
BufferedReader strin=new BufferedReader(new InputStreamReader(System.in));
int a = Integer.parseInt(strin.readLine());
print(arr,a);
}
public static void print(int[] arr,int a){
int count = 0;
for(int i=0;i<arr.length;i++){
if(arr[i]==a){
System.out.println(i);
}else{
count++;
}
}
if(count==arr.length){
System.out.println("-1");
}
}