forked from IF-LK-2020/array
Finished max()
This commit is contained in:
10
Arrays.java
10
Arrays.java
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user