Home >>Java Programs >Java Program to print the smallest element in an array
In this example, we will create a java program to find out the smallest element present in the array. This can be done by defining a variable min which initially will hold the value of the first element. Then we will loop through the array by comparing the value of min with elements of the array. If any of the element's value is less than min then store the value of the element in min.
Algorithm
Program:
public class Main
{
public static void main(String[] args)
{
int [] arr = new int [] {35, 11, 17, 53, 61, 43, 94, 51, 32, 87};
int min = arr[0];
for (int i = 0; i < arr.length; i++)
{
if(arr[i] <min)
min = arr[i];
}
System.out.println("Smallest element present in given array: " + min);
}
}
Output
Smallest element present in given array: 11