public class SafeArray{
private int[] arr;
public SafeArray(){
this(10);
}
public SafeArray(int length){
arr=new int[length];
}
public void showElement(){
for(int i:arr){
System.out.print(i+" "):
}
}
public void getElement(int i){
if(i>=arr.length||i<0){
System.err.println("索引错误");
return 0;
}
return arr[i];
}
public int getLength(){
return arr.length;
}
public void setElement(int i,int data){
if(i>=arr.length||i<0){
System.err.println("索引错误");
return;
}
arr[i]=data;
}
}