# Find the second smallest integer in array

**Problem statement**

Given an array of integers, find the second smallest integer in that array.

**Solution**

public class SecondSmallestInteger { public static int solve(int[] arr) { int smallest = Integer.MAX_VALUE; int secondSmallest = Integer.MAX_VALUE; ; for (int i = 0; i < arr.length; i++) { if (arr[i] < smallest) { secondSmallest = smallest; smallest = arr[i]; } else if (arr[i] == smallest) { secondSmallest = smallest; } else if (arr[i] < secondSmallest) { secondSmallest = arr[i]; } } return secondSmallest; } public static void main(String[] args) { int[] arr = { 1, 2, -7, 10, 100, 999, 2, 0, 34, 42 }; int ans = solve(arr); Arrays.sort(arr); if (ans == arr[1]) { System.out.println(ans); } else { System.out.println("Problem"); } } }