Opening Hours :7AM to 9PM
class ArraySmallest { public int findSmallest(int[] arr, int n) { int smallest = Integer.MAX_VALUE; for (int i = 0; i < n; i++) { if (arr[i] < smallest) { smallest = arr[i]; } } return smallest; } } public class Main { public static void main(String[] args) { ArraySmallest ar=new ArraySmallest(); int[] arr = {1, 14, 2, 16, 10, 20, 5}; int n = arr.length; int smallest =ar.findSmallest(arr, n); System.out.println("Smallest element is " + smallest); } }In this program, The findSmallest method takes two arguments; the array, and the length of the array.