面向对象方法传参实现数组求和,求平均值

package ch11;

/**
* Created by liwenj on 2017/7/21.
*/
public class T1 {
public int getTotal(int[] scores){
int total=0;
for(int i=0;i<scores.length;i++){
total=total+scores[i];
}
return total;
}
public int get(int weight){
return weight;
}
public double avgm(int[] scores){
int total=getTotal(scores);
double aver=total*1.0/scores.length;
return aver;
}

public static void main(String[] args) {
T1 t1=new T1();
int w=t1.get(20);
int[] s=new int[]{1,2,3,4,5,6,7,8,9,10};
int total=t1.getTotal(s);
System.out.println(total);
double c=t1.avgm(s);
System.out.println(c);
}
}
posted @ 2017-07-21 10:28  斯丢皮德曼  阅读(416)  评论(0编辑  收藏  举报