编写程序:选择排序
-
初始化大小为16的byte类型数组(30分)
-
使用for循环给数组赋值(随机数)(30分)
-
使用选择排序对赋值后的数组进行降序排序(40分)
public static void main(String[] args) {
// write your code here
//1.初始化大小为16的byte类型数组(30分)
byte[] by = new byte[16];
//2. 使用for循环给数组赋值(随机数)(30分)
for(int i = 0;i<16;i++){
by[i] = (byte)(Math.random()*10);
}
System.out.println("随机生成数");
for(int i =0;i<16;i++){
System.out.print(by[i]+" ");
}
System.out.println("");
//3. 使用选择排序对赋值后的数组进行降序排序(40分)
System.out.println("进行降序排序");
Arrays.sort(by);
for(int i=by.length-1;i>=0;i--){
System.out.print(by[i]+" ");
}
}