Given an array the task is to find the largest element present in the array.
Example: Consider an array with data {5, 1, 0, 9, 4}. The program should find the smallest element from this array which is 0.
Java
import java.util.*;
public class SmallestElement
{
public static void main(String args[])
{
int size=0,min=0;
Scanner sc=new Scanner(System.in);
System.out.print("Enter array size: ");
size=sc.nextInt();
int ar[]=new int[size];
System.out.println("Enter array elements:-");
for(int i=0;i<size;i++)
{
ar[i]=sc.nextInt();
}
min=ar[0];
for(int i=0;i<size;i++)
{
if(ar[i]<min)
{
min=ar[i];
}
}
System.out.println("The smallest element in the array is "+min);
}
}Java