Current location - Training Enrollment Network - Mathematics courses - Publicity of average score in mathematics
Publicity of average score in mathematics
Stream, a new feature of Java8, is strongly recommended to solve this kind of problem of finding statistical results. It's really convenient, and the code is concise and elegant.

IntSummaryStatistics class is used, which contains all kinds of statistical results mentioned in this question.

List & lt students & gt? List? =? Arrays.asList (new? Student (100),? New? Student (59)? New? Student (80), New? Student (92));

IntSummaryStatistics? Summary statistics? =? list.stream()。 mapToInt(Student::getScore)。 summary statistics();

System.out.println ("Maximum score:"? +? summary statistics . get max());

System.out.println ("Minimum score:"? +? summary statistics . getmin());

System.out.println ("Total score:"? +? summarystatistics . getsum());

System.out.println ("average score:"? +? summary statistics . get average()); You can refer to it