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