Scanner scn=new Scanner(System.in);
int p=scn.nextInt();
System.out.println("请输入"+p+"个数字:");
int arr[]=new int[p];
for(int k=0;k<p-1;k++)
{
arr[k]=scn.nextInt();
}
for(int i=0;i<arr.length-1;i++)
{
for(int j=0;j<arr.length-1;j++)
{
if(arr[j]>arr[j+1])
{
int t=arr[j];
arr[j]=arr[j+1];
arr[j+1]=t;
}
}
}
if(arr.length%2!=0)
{
int mid=(arr.length+1)/2;
System.out.println("输出其中位数为:"+arr[mid]);
}
else
{
int mid1=arr.length/2;
int mid2=mid1+1;
System.out.println("输出其中位数为:"+(double)(arr[mid1]+arr[mid2])/2.0);
}
04-24
3万+
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
08-23
6305
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)