File tree Expand file tree Collapse file tree 1 file changed +5
-13
lines changed
src/main/java/com/thealgorithms/maths Expand file tree Collapse file tree 1 file changed +5
-13
lines changed Original file line number Diff line number Diff line change 11package com .thealgorithms .maths ;
22
33public final class FindMax {
4- private FindMax () {
5- }
4+ private FindMax () {}
65
7- /**
8- * @brief finds the maximum value stored in the input array
9- *
10- * @param array the input array
11- * @exception IllegalArgumentException input array is empty
12- * @return the maximum value stored in the input array
13- */
146 public static int findMax (final int [] array ) {
15- int n = array .length ;
16- if (n == 0 ) {
7+ if (array .length == 0 ) {
178 throw new IllegalArgumentException ("Array must be non-empty." );
189 }
10+
1911 int max = array [0 ];
20- for (int i = 1 ; i < n ; i ++) {
21- max = Math .max (array [i ] , max );
12+ for (int i = 1 ; i < array . length ; i ++) {
13+ max = Math .max (array [i ], max );
2214 }
2315 return max ;
2416 }
You can’t perform that action at this time.
0 commit comments