forked from IF-LK-2020/array
avg() finished
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user