是否可以对以下代码的随机生成的整数数组进行排序(升序)?如果,那怎么样?
import java.util.Random;
public class RandomArraySorter {
public static void main(String args[]){
Random random = new Random();
int array[] = new int[10];
//number of integer spaces within the array:
for(int i = 0; i < 10; i++){
//random numbers from 1 to 100:
array[i] = random.nextInt(100) + 1;
System.out.print(array[i] + " ");
}
} //end of main
} //end of class
答案 0 :(得分:2)
您可以使用以下方式排序:
Arrays.sort(array);