請提供一個方法,可以傳入任意個數的整數,並傳回這些整數的小到大排序後結果

import java.io.*;

class arr{
   
  public static int[] sortArr(int[] sort){
    int temporary;
    for(int i=0;i<sort.length;i++){
      for(int n=0;n<sort.length-1;n++){
        if (sort[n]>sort[n+1]){
          temporary = sort[n+1];
          sort[n+1] = sort[n];
          sort[n] = temporary;
        }
      }
    }
    return sort;
  }
}

public class app2{
  public static void main(String[] argv)
  throws IOException {
    BufferedReader br = new BufferedReader (
    new InputStreamReader(System.in));
 
    System.out.print("請輸入任意數的數量:");
    int length = Integer.parseInt(br.readLine());
    int[] a = new int[length];
    int n = 0;
 
    while (n < length){
      System.out.print("請輸入第" + (n+1) + "個數:");
      int num = Integer.parseInt(br.readLine());
      a[n] = num;
      n++;
    }
 
    int[] output=arr.sortArr(a);
    for(int i=0;i<output.length;i++){
        System.out.print(output[i]+" ");
    }
  }
}

 

 

 


 

(不好意思小宣傳一下我的繪圖 希望大家喜歡)

 

\\

這是我的海苔貓粉專

www.facebook.com/norinekocat/

 

海苔貓IG

海苔貓Instagram

 

謝謝大家:))

裡面有許多繪圖作品~ 希望大家支持我會繼續努力

請多多指教哦

 

 

ps

p新的貼圖終於出來了💜💜💜可愛的海苔貓-第三代

 

海苔貓繪圖作品\\

希望大家支持~~

arrow
arrow
    全站熱搜

    海苔貓Nori 發表在 痞客邦 留言(0) 人氣()