用 java语言设计程序

各位大佬帮帮忙
2024-11-07 07:19:45
推荐回答(2个)
回答1:

按照题目要求编写的求平均分的Java程序如下:

import java.util.Scanner;

import java.util.Arrays;

public class F {

 public static void main(String[] args) {

  Scanner sc=new Scanner(System.in);

  int n=sc.nextInt();

  int a[]=new int[n];

  for(int i=0;i

   a[i]=sc.nextInt();

  }

  Arrays.sort(a);

  int sum=0;

  for(int i=1;i

   sum=sum+a[i];

  }

  System.out.println(sum/(n-2));

 }

}

回答2:

Scannner scanner = new Scanner(System.in);
int N = scanner.nextInt();
int[] nums = new int[N];
for(int i = 0; i nums[i] = scanner.nextInt();

}
//导入Arrays所在的包

Arrays.sort(nums);
int sum = 0;
for(int j=0;j sum+=nums[j];
}
int avg = sum/nums.length-2;