//数组为nums
String[] numStrings = nums.split(",");
int total = 0;
for (String numString:numStrings){
int num = Integer.parseInt(numString);
total += num;
}
double average = (double)total/numStrings.length;
long roundedAverage = Math.round(average);
//这个roundedAverage 就是最终得数
求一个数组里的数相加算平均数
于 2024-04-12 09:22:30 首次发布