本帖最后由 18643448863 于 2014-10-9 07:40 编辑
- class maoPao
- {
- public static void maopao(int[] arr)
- {for(int x=0;x<arr.length;x++)
- {
- for(int y=0;y<arr.length-x;y++)
- {
- if(arr[y]>arr[y+1])
- {int z= arr[y];
- arr[y]=arr[y+1];
- arr[y+1]=z;}
- }
- }
- }
- public static void main(String[] args)
- {int [] arr={7,1,6,4,2,8,3};
- maopao(arr);
- paixudayin(arr);}
- public static void paixudayin(int[] arr)
- {
- System.out.print("[");
- for(int x=0;x<arr.length;x++)
- { if(x!=arr.length-1)
- System.out.print(arr[x]+",");
- else
- System.out.print(arr[x]+"]");}
- }
- }
复制代码
F:\java练习代码\day02>java maoPao
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 7
at maoPao.maopao(maopao.java:14)
at maoPao.main(maopao.java:24)
怎么个情况 |
|