class Ascending { public static void main(String args[]) { String[] a = { "4", "9", "2", "1", "7", "3"}; int[] b = new int[5]; int i; for( i=0; i<a.length; i++) { System.out.println("get the values:" +a[i]); b[i] = Integer.parseInt(a[i]); System.out.println("......."); } for(i=0; i<b.length; i++) { for(int j=0; j>i; j++) { if(b[i]>=b[j]) { System.out.println("hi"); System.out.println(+b[i]); } } } System.out.println("*"); } } C:\Program Files\java\jdk1.5.0_05\bin>java Ascending get the values:4 ....... get the values:9 ....... get the values:2 ....... get the values:1 ....... get the values:7 ....... get the values:3 Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 5 at Ascending.main(Ascending.java:11)
|