forked from IF-LK-2020/array
max
This commit is contained in:
@@ -123,8 +123,17 @@ public class Arrays {
|
||||
* Für ein leeres Array wird 0 zurück gegeben.
|
||||
*/
|
||||
public int max( int[] pArray ) {
|
||||
if (pArray == null || pArray.length == 0) {
|
||||
return 0;
|
||||
}
|
||||
int max = pArray[0];
|
||||
for (int i = 0 ; i < pArray.length; i++) {
|
||||
if (pArray[i] > max) {
|
||||
max = pArray[i];
|
||||
}
|
||||
}
|
||||
return max;
|
||||
}
|
||||
|
||||
/**
|
||||
* Berechnet die Summe aller Elemente in
|
||||
|
||||
Reference in New Issue
Block a user