public class Test16 {标签:arr,scanner,摸索,double,代码,System,println,out,成就感 From: https://www.cnblogs.com/ningbaoer/p/17298281.html
public static void main(String[] args) {
//5、定义一个长度为5的double型数组。
// 循环输入5个double型的无序数据,
// 将些数组进行从大到小排列。
double[] arr = new double[5];
Scanner scanner = new Scanner(System.in);
System.out.println("输入5个double型的无序数据");
int i ;
for (i = 0;i <arr.length;++i) {
arr[i] = scanner.nextDouble();
}
System.out.println("你已经输入完五个数据");
for (i = 0;i <arr.length;++i) {
System.out.print( arr[i] + "\t");
}
//排序
System.out.println("下面开始从大到小排序");
for ( i= 0;i<arr.length;++i){
for (int j =i +1;j<arr.length;++j){
if (arr[i]<arr[j]){
double temp = arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
}
}
System.out.println("从大到小排列为 :");
for (i = 0;i <arr.length;++i) {
System.out.print(arr[i] + "\t");
}
scanner.close();
}
}