Find the smallest and largest element from the array in java - BSC IT PRACTICALS

Friday, January 19, 2018

Find the smallest and largest element from the array in java


CODE:

class prac3C
{
  public static void main(String args[])
  {
  
     int num[]=new int[]{10,20,30,5};
int s=num[0];
int l=num[0];
for(int i=0;i<num.length;i++)
{
    if(l<num[i])
{
  l=num[i];
  }
  else
  {
    s=num[i];
}
}
System.out.println("Largest Number are:"+l);
System.out.println("Smallest number are: "+s);

}}

No comments:

Post a Comment