- import java.util.*;
- import java.io.*;
- class ArrayDemo
- {
- public static void main(String[] args) throws Exception
- {
- BufferedReader bis =
- new BufferedReader(new InputStreamReader(System.in));
- int[] arr = new int[1024];
- String line=null;
- int index = 0;
- while((line=bis.readLine())!=null)
- {
- if(line.equals("over"))
- break;
- arr[index++] = Integer.parseInt(line);
- }
- int[] newArr = new int[index];
- System.out.print("排序前数组:[");
- for(int i=0;i<index;i++)
- {
- newArr[i]=arr[i];
- if(i!=index-1)
- System.out.print(newArr[i]+",");
- else
- System.out.println(newArr[i]+"]");
- }
-
- Arrays.sort(newArr);
- System.out.print("排序后数组:[");
- for(int i=0;i<index;i++)
- {
- if(i!=index-1)
- System.out.print(newArr[i]+",");
- else
- System.out.println(newArr[i]+"]");
- }
- }
- }
复制代码 |