public static void main(String[] args) {
int avg=0,sum=0,percentage=0;
Scanner input = new Scanner(System.in);
int[]arr=new int [6];
System.out.println("Enter all the elements: ");
for(int i=0; i<6; i++)
{
arr[i]=input.nextInt();
sum+=arr[i];
avg=sum/6;
}
System.out.println("Average is: "+avg);
for(int i=0;i<arr.length;i++)
{
if(arr[i]>avg)
{
percentage=(arr[i]*100/6);
}
}
System.out.println("Percentage is: "+percentage+"%");
}
例如,如果数组中有 3 个元素大于平均值,则百分比为 3*100/6=50%
当年话下
茅侃侃
慕哥6287543
慕容森
喵喔喔
相关分类