while True: n=int(input()) a=list(map(int,input().split())) sum=0 a.sort() for i in range(0,len(a)-1): sum+=a[i]*(len(a)-i-1) m=sum/n print('%.2f'%m)转为java代码
时间: 2023-12-10 14:40:58 浏览: 124
Python期末试题A.docx
```
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while (true) {
int n = scanner.nextInt();
if (n == 0) {
break;
}
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = scanner.nextInt();
}
Arrays.sort(a);
double sum = 0;
for (int i = 0; i < n - 1; i++) {
sum += a[i] * (n - i - 1);
}
double m = sum / n;
System.out.printf("%.2f\n", m);
}
}
}
```
阅读全文