java 计算列表标准差
import java.util.List; public class StdDevCalculator { public static double calculateStdDev(List<Double> numbers) { if (numbers.isEmpty()) { return 0; } double avg = numbers.stream().mapToDouble(Double::doubleValue).average().getAsDouble(); double sum = numbers.stream().map(n -> Math.pow(n - avg, 2)).mapToDouble(Double::doubleValue).sum(); return Math.sqrt(sum / numbers.size()); } public static void main(String[] args) { List<Double> numbers = List.of(1.0, 2.0, 3.0, 4.0, 5.0); double stdDev = calculateStdDev(numbers); System.out.println("Standard Deviation: " + stdDev); } }