1 package javaproject; 2 3 public class DeleteData { 4 5 public boolean delete(int[] a,int i) 6 { 7 int len=a.length; 8 if(i<0||i>len) 9 return false; 10 else 11 { 12 try 13 { 14 for(int j=i;j<len-1;j++) 15 { 16 a[j]=a[j+1]; 17 } 18 } 19 catch(ArrayIndexOutOfBoundsException e ) 20 { 21 System.out.println("数组越界"); 22 } 23 return true; 24 } 25 } 26 public static void main(String [] args) 27 { 28 // TODO Auto-generated method stub 29 DeleteData b=new DeleteData(); 30 int a[]={1,2,3,5,6,7}; 31 try{ 32 System.out.println("array a:"+a[0]+" "+a[1]+" "+a[2]+" "+a[3]+" "+a[4]+" "+a[5]); 33 b.delete(a,3); 34 System.out.println("删除a[3]:"+a[0]+" "+a[1]+" "+a[2]+" "+a[3]+" "+a[4]); 35 }catch(ArrayIndexOutOfBoundsException e ) 36 { 37 System.out.println("数组越界"); 38 } 39 } 40 }