zw731129 2007-11-19 21:24
有懂java buleJ的吗?请教个问题啊~急!!
有一组数字.从1 到20,用addNumber (int A[]),获取它的和.,再用findAverage (??)获取和的平均值,再打印出来结果.
Write a Java program or class called “AddN”that finds the average of n numbers, where these numbers are stored in an n-dimensional array and n<= 20 (Nis between 1 and 20).
Your program should include the following methods
(1)
THE class should initialize the array A in its constructor
(2)
initialiseNumbers (int A[]), stores the n numbers in an array A
(3)
addNumbers (intA[]), returns the sum of all the numbers in array A.
(4)
findAverageg (??),returns the aerage value of the arrayh sum of elements in A, where ?? is up to the programmer to decide whatever is to be used as parameters or maybe not (optional case for you!)
(5)
use the public static void main method to run this program by making an instance of AddN and calling these methods
2. you are then asked to write a program that finds the square root of the average of n numbers. Given that you are required to use inheritance in this case, write program code for doing this and run the new program”RootAddN”using the same data array A. State what methods/constructors can be overridden if any, and any additional methods. Note root of a number is obtained by using given by java.lang.Math.sqrt(a)
现在编的如下————————————————
public class AvgN{
public AvgN(){
int []A = {1,3,6,7,9,12,16,19};
}
public int addNumbers(int[]A)
{
int sum=0;
for (int i=0; i<A.length; i++)
sum +=A;
return sum;
}
public double findAverage ()
{
int sum=0;
int []A = {1,3,6,7,9,12,16,19};
for (int i=0; i<A.length; i++)
sum +=A;
return sum/A.length;
}
public static void main (String[]args){
AvgN avg= new AvgN();
int []A = {1,3,6,7,9,12,16,19};
System.out.println ("The average of all the numbers in Array = " + avg.findAverage());
System.out.println ("The sum of all the numbers in Array = " + avg.addNumbers(A));
}
}
问题是————
为什么产生一个对象以后,addNumber (int[]A) 不可以用?
有谁能帮帮我~帮看下问题出在那???谢谢了!!!