public class ArraysDome {
public void forDome(int[] arr){
for(int i=0;i<arr.length;i++){
System.out.println(arr[i]);
}
}
public int indexOf(int[]arr,int index){
int num=0;
for(int i=0;i<arr.length;i++){
if(arr[i]==index){
num=i;
}
}
return num;
}
}
package cn.itcast;
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int[] arr = {98,23,16,35,72};
ArraysDome ad=new ArraysDome();
ad.forDome(arr);
System.out.println("-----------------------");
System.out.println(ad.indexOf(arr, 23));
}
}
|
|