Sort an array in Java

后端 未结 17 1231
傲寒
傲寒 2020-11-22 04:53

I\'m trying to make a program that consists of an array of 10 integers which all has a random value, so far so good.

However, now I need to sort them in order from l

17条回答
  •  闹比i
    闹比i (楼主)
    2020-11-22 05:13

    MOST EFFECTIVE WAY!

    public static void main(String args[])
    {
        int [] array = new int[10];//creates an array named array to hold 10 int's
        for(int x: array)//for-each loop!
          x = ((int)(Math.random()*100+1));
        Array.sort(array);
        for(int x: array)
          System.out.println(x+" ");
    }
    

提交回复
热议问题