首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

java基础——数组中的查寻

2012-10-06 
java基础——数组中的查找class Found{public static void main(String[] args){int[] arr{1,2,3,4,5,6,7}

java基础——数组中的查找
class Found{
public static void main(String[] args){
int[] arr={1,2,3,4,5,6,7};

int temp=found(arr,43);
if(temp==-1){
System.out.println("没有该数据");
}
else{
System.out.println(temp);
}

}
         //获取key值第一次出现在数组中的位置
public static int found(int arr[],int key){
for(int x=0;x<arr.length;x++){
if(arr[x]==key)
return x;

}
return -1;
}

}

热点排行