tyrochen
发贴: 3
积分: 0
|
于 2008-03-17 08:31
源代码如下: import java.io.*; class ArraySort {public static void main(String[] args) throws IOException {BufferedReader keyin =new BufferedReader(new InputStreamReader(System.in)); int a[],i, j, k, temp; String c; System.out.println("Input the number of array elements!"); c=keyin.readLine(); temp=new Integer.intValue();//temp=Integer.parseInt; a = new int[temp]; System.out.println("Input "+ temp +" numbers. One per line!"); for ( i=0; i<a.length; i++) { c=keyin.readLine();int d=new Integer.intValue(); a[i]=d; } System.out.println("After sorting!"); for ( i=0; i<a.length-1; i++) {k = i; for( j = i + 1 ; j< a.length; j++) if (a[j]< a[k] ) k = j; temp = a[i]; a[i]= a[k]; a[k] = temp; } for ( i=0; i<a.length; i++) System.out.println("第"+i+"个数组元素a"+i+"是:"+a[i]); } }
运行结果显示异常。本意是要进行数组元素值的输入,并完成排序;但总在输入输入第一个元素后、按下回车并接着输入第二个元素时出错:NumberFormatException。请各位高手指点,不胜感激。
|