23 lines
367 B
Java
23 lines
367 B
Java
|
public class Moyenne{
|
||
|
private double total=0;
|
||
|
private long cpt=0;
|
||
|
|
||
|
public void add(Number val){
|
||
|
total += val.doubleValue();
|
||
|
++cpt;
|
||
|
}
|
||
|
|
||
|
public double getAverage(){
|
||
|
if (cpt==0){
|
||
|
return 0;
|
||
|
}
|
||
|
return total/cpt;
|
||
|
}
|
||
|
|
||
|
public static void main(String[] args) {
|
||
|
Moyenne m = new Moyenne();
|
||
|
m.add(5.5);
|
||
|
m.add(10);
|
||
|
System.out.println(m.getAverage());
|
||
|
}
|
||
|
}
|