返回列表 發帖
  1. import java.io.BufferedReader;
  2. import java.io.InputStreamReader;
  3. import java.util.Arrays;

  4. public class P5 {

  5.     int n[], len;
  6.     BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
  7.     String raw[];

  8.     P5() throws Exception
  9.     {
  10.         System.out.print("請輸入多個整數 (以空白分隔):");
  11.         raw=br.readLine().split(" ");
  12.         len=raw.length;
  13.         n=new int[len];
  14.         for(int i=0; i<len; i++)
  15.             n[i]=Integer.parseInt(raw[i]);
  16.         Arrays.sort(n);
  17.         System.out.print("排序後:");
  18.         for(int i=0; i<len; i++)
  19.             System.out.print(n[i]+" ");
  20.         System.out.println();
  21.     }

  22.     public static void main(String[] args) throws Exception {
  23.         new P5();
  24.     }
  25. }
複製代碼

TOP

返回列表