import java.util.*;

public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); Set scores = new HashSet<>();

    System.out.println("请输入学生成绩,输入-1结束输入:");
    int score = scanner.nextInt();
    while (score != -1) {
        scores.add(score);
        score = scanner.nextInt();
    }

    Integer[] scoreArray = scores.toArray(new Integer[0]);
    Arrays.sort(scoreArray);

    System.out.println("学生成绩升序排列为:");
    for (int i = 0; i < scoreArray.length; i++) {
        System.out.print(scoreArray[i] + " ");
    }
}
定义一个集合来保存从控制台输入的多个学生成绩用toArray转化为数组升序排序 用java写

原文地址: https://www.cveoy.top/t/topic/hevG 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录