Table of Contents
Find the smallest and largest element from the array in java
This simple java program will demonstrate how to get largest number and smallest number from array.
Java program to find largest and smallest number from the array
import java.util.*;
class Demo
{
public static void main(String args[])
{
int i,sml,lrg;
int num[] = new int[]{21,486,2,35,45,88,222,14,59,458,756,124};
sml = lrg = num[0];
for(i=0;i<num.length;i++)
{
if(num[i]<sml)
{
sml = num[i];
}
if(num[i]>lrg)
{
lrg=num[i];
}
}
System.out.println("Smallest number is " + sml );
System.out.println("Largest number is " + lrg );
}
}
Output

PRACTICALS/PRACTICE PROGRAM IN Java
CHECKOUT OTHER RELATED TOPICS
We are aiming to explain all concepts of Java in easiest terms as possible.

ITVoyagers
Author