编写一个程序,找到大于平均值的项的数目
生活随笔
收集整理的這篇文章主要介紹了
编写一个程序,找到大于平均值的项的数目
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
package seven_1;
import java.util.*;
public class seven_7_3 {public static void main(String[] args) {Scanner input=new Scanner(System.in);System.out.println("Enter the number of items :");int n=input.nextInt();//輸入一個你想要輸入的位數;double[] numbers=new double[n];//聲明了numbers,創建了n個double型元素的數組,并將引用賦給numbers;/*在c語言中是不允許的,c語言里的數組聲明的大小必須是常量*/double sum=0;System.out.print("Enter the numbers:");for(int i=0;i<n;i++){numbers[i]=input.nextDouble();sum+=numbers[i];}double average=sum/n;int count=0;for(int i=0;i<n;i++){if(numbers[i]>average)count++;}System.out.println("Average is" + average);System.out.println("Number of elements above the average is" + count);}}
總結
以上是生活随笔為你收集整理的编写一个程序,找到大于平均值的项的数目的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Python学习之共享引用
- 下一篇: Python学习之zip函数