6-17 编程练习题答案

来源:互联网 发布:淘宝网 电脑版 官网 编辑:程序博客网 时间:2024/06/05 04:41
import java.util.Scanner;public class Test{public static void main(String[] args){Scanner input = new Scanner(System.in);System.out.print("Enter ten doubles: ");double[] list = new double[10];for(int i = 0; i < 10; i++)list[i] = input.nextDouble();selectionSort(list);System.out.print("After sorted, the list are: ");for(double tmp: list)System.out.print(tmp + " ");}public static void selectionSort(double[] list){for(int i = 0; i < list.length - 1; i++){for(int j = i + 1; j < list.length; j++){if(list[j] > list[i]){double tmp = list[i];list[i] = list[j];list[j] = tmp;}}}}}

0 0
原创粉丝点击