forked from IF-LK-2020/array
sum
This commit is contained in:
@@ -142,8 +142,15 @@ public class Arrays {
|
|||||||
* Für ein leeres Array wird 0 zurück gegeben.
|
* Für ein leeres Array wird 0 zurück gegeben.
|
||||||
*/
|
*/
|
||||||
public int sum( int[] pArray ) {
|
public int sum( int[] pArray ) {
|
||||||
|
if (pArray == null || pArray.length == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
int sum = 0;
|
||||||
|
for (int i : pArray) {
|
||||||
|
sum += i;
|
||||||
|
}
|
||||||
|
return sum;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Berechnet den Mittelwert (average) eines
|
* Berechnet den Mittelwert (average) eines
|
||||||
|
|||||||
Reference in New Issue
Block a user