各位高手,刚用eclipse敲的一个代码(是一个例子),但是我在输入1~10,软件就将结果显示出来了,而NUMBER_OF_ELEMENTS = 20;这个怎么解释呢?
import java.util.Scanner;
public class AnalyzeNumbers
{
public static void main(String[] args)
{
final int NUMBER_OF_ELEMENTS = 20;
double [] numbers = new double [NUMBER_OF_ELEMENTS];
double sum = 0;
Scanner input = new Scanner(System.in);
//求和
for(int i=0; i<NUMBER_OF_ELEMENTS; i++)
{
System.out.print("Enter your new number: ");
numbers[i] = input.nextDouble();
sum += numbers[i];
i++;
}
//求平均值,并得出大于平均值的个数
double average = sum / NUMBER_OF_ELEMENTS;
int count = 0;
for(int i=0; i<NUMBER_OF_ELEMENTS; i++)
{
if(numbers[i] > average)
count++;
}
System.out.println("The sum is "+sum);
System.out.println("Average is "+average);
System.out.println("Number of elements above the average is: "+count);
}
}
|
|