avg() finished

This commit is contained in:
artem.didytschuk
2020-08-31 22:39:59 +02:00
parent b8abf25cf2
commit 02553bdf9f

View File

@@ -160,8 +160,15 @@ public class Arrays {
* Für ein leeres Array wird 0 zurück gegeben.
*/
public double avg( int[] pArray ) {
if( pArray.length == 0 ) {
return 0;
}
double sum = 0;
for( int i = 0; i < pArray.length; i++ ) {
sum += pArray[i];
}
return sum/pArray.length;
}
/**
* Prüft, ob <b>alle</b> Elemente in einem Array von