Finding the minimum value of an array

Just set a variable min to the maximum value possible that your type can contain, for example min = Integer.MAX_VALUE; for an integer array and then loop through all the array’s elements reassigning min every time a lower 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, 1, 3, 5, 7, 9 };
 
      System.out.println("Minimum: " + findMin(arr));
   }
 
   public static int findMin(int[] arr) {
      int min = Integer.MAX_VALUE;
      for (int i=0; i<arr.length; i++) {
         if (arr[i] < min) {
            min = arr[i];
         }
      }
      return min;
   }
}