Finished max()

This commit is contained in:
artem.didytschuk
2020-08-31 22:27:42 +02:00
parent 2f9676749f
commit 027abe4550

View File

@@ -123,9 +123,19 @@ public class Arrays {
* Für ein leeres Array wird 0 zurück gegeben.
*/
public int max( int[] pArray ) {
if( pArray.length == 0 ) {
return 0;
}
int max = pArray[0];
for( int i = 1; i < pArray.length; i++ ) {
if( pArray[i] > max ) {
max = pArray[i];
}
}
return max;
}
/**
* Berechnet die Summe aller Elemente in
* einem Zahlen-Array.