Need Java array help using scanner class to output an average and sort method

后端 未结 4 2188
一整个雨季
一整个雨季 2020-12-04 03:35

After several hours, I haven\'t made progress on making a method to output the average. I also need to make a sort class. Overall, the assignment needs.

Develop meth

4条回答
  •  臣服心动
    2020-12-04 04:33

    In Java 8+ you could use IntStream and IntSummaryStatistics like

    int[] arr = { 3, 1, 2 };
    IntSummaryStatistics stats = IntStream.of(arr).summaryStatistics();
    System.out.printf("Min: %d, Max: %d, Average: %.2f%n", //
            stats.getMin(), stats.getMax(), stats.getAverage());
    IntStream.of(arr).sorted().forEach(System.out::println);
    

提交回复
热议问题