用Array寫一個程式輸入10個數字,計算他們的平均且找出幾個是比平均大的
謝謝!!!!!
2007-12-09 06:07:57 · 1 個解答 · 發問者 花兒 1 in 電腦與網際網路 ➔ 程式設計
//Power by Eclipse
//Download Site: http://www.eclipse.org/
import java.io.*;
import java.util.*;
public class TEST
//檔名:TEST.java
{
public static void main(String[] args)
{
PrintStream o=new PrintStream(System.out);
Scanner in=new Scanner(System.in);
int MAX=10;
double n[]=new double[MAX];
double b[]=new double[MAX];
for(int i=0;i
o.printf("Input %d Number: ",i+1);
n[i]=in.nextDouble();
}
double ave=average(MAX,n);
int got=who_is_your_daddy(b,MAX,n,ave);
o.printf("Average= %f\nAll got %d item%s.\n",ave,got,(got>1?"s":""));
for(int i=0;i
o.printf("Got %f\n",b[i]);
}
}
public static double average(int Len, double n[])
{
double ave=0;
for(int i=0;i
ave+=n[i];
}
return ave/Len;
}
public static int who_is_your_daddy(double buffer[], int Len, double n[], double average)
{
int j=0;
for(int i=0;i
if(n[i]>average)
{
buffer[j]=n[i];
j++;
}
}
return j;
}
}
2007-12-09 07:42:09 · answer #1 · answered by Big_John-tw 7 · 0⤊ 0⤋