Advertisement
Aldin-SXR

getMax()

Apr 24th, 2020
321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.28 KB | None | 0 0
  1. /* Find the maximum element in the array */
  2. private static int getMax(int[] elements) {
  3.     int max = elements[0];                          // 1
  4.     for (int i = 1; i < elements.length; i++) {     // 2
  5.         if (elements[i] > max) {                    // 3
  6.             max = elements[i];                      // 3
  7.         }
  8.     }
  9.     return max;                                     // 4
  10. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement