- import java .util.Arrays;
- import java .io.Console;
- public class ch45
- {
- public static void main(String args[])
- {
- int a[]=new int[10];
- Console c=System.console();
- System.out.println("請任意輸入10個整數");
- for(int i=0; i<10; i++)
- {
- System.out.print("第"+(i+1)+"個數: ");
- a[i]=Integer.parseInt(c.readLine());
- }
- Arrays.sort(a);
- System.out.println("你剛輸入的十個數字由小到大依序為: ");
- for(int i=0; i<=9; i++)
- {
- System.out.print(a[i]+" ");
- }
- }
- }
複製代碼 |