Find the maximum value of an array

Just set a variable max to the minimum value possible that your type can contain, for example max = Integer.MIN_VALUE; for an integer array and then loop through all the array’s elements reassigning max every time a higher value is found.

Main.java:

import java.util.*;
import java.io.*;
 
public class Main
{
   public static void main(String []args) {
      int arr[] = { 10, 8, 6, 4, 2, 11, 3, 5, 7, 9 };
 
      System.out.println("Maximum: " + findMax(arr));
   }
 
   public static int findMax(int[] arr) {
      int max = Integer.MIN_VALUE;
      for (int i=0; i<arr.length; i++) {
         if (arr[i] > max) {
            max = arr[i];
         }
      }
      return max;
   }
}