题解 | #明明的随机数#

明明的随机数

https://www.nowcoder.com/practice/3245215fffb84b7b81285493eae92ff0

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        int n = in.nextInt();

        HashSet<Integerset = new HashSet<>();
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int sc = in.nextInt();
            set.add(sc);
        }
        Integer[] arr = set.toArray(new Integer[0]);
        for (int i = arr.length; i > 0; i--) {
            for (int j = 0; j < i-1; j++) {
                Integer a = arr[j];
                if (a > arr[j+1]) {
                    arr[j] = arr[j+1];
                    arr[j+1] = a;
                } 
            }
        }
        for (Integer aa : arr) {
            System.out.println(aa);
        }
    }
}
#java#
全部评论

相关推荐

04-08 21:39
已编辑
Java
点赞 评论 收藏
分享
03-10 16:35
门头沟学院 Java
hxyz61:问他要个微信,这里不方便骂人
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务