[CODE]我也刚学...写了一下..你看看...
public class theArrayClass{
public static void main(String[] args){
theArray myArray = new theArray(50);
myArray.setArrayValue();
int intArraySum = myArray.arraySum();
System.out.println("和是:" + intArraySum);
myArray = null;
System.gc();
}
}
class theArray{
private int[] MyIntArray;
public theArray(){
MyIntArray = new int[10];
}
public theArray(int length){
MyIntArray = new int[length];
}
public void setArrayValue(){
for(int i=0;i<MyIntArray.length;i++){
MyIntArray[i] = (int )(Math.random() * 10 ) % 2;
}
}
public int arraySum(){
int sum =0;
for(int i=0;i<MyIntArray.length;i++){
sum += MyIntArray[i];
}
return sum;
}
}
[/CODE]