Smallest among array elements



CODE:
import java.util.*;
class Small
{
     public static void main(String args[])
     {
           int i,n,small;
           Scanner sc = new Scanner(System.in);
           System.out.println("Enter number of elements:");
           n=sc.nextInt();
           int a[]=new int[n];
           for(i=0;i<=n-1;i++)
           {
                System.out.print("enter a no:");
                a[i]=sc.nextInt();
           }
           small=a[0];
           for(i=0;i<=n-1;i++)
           {
                if(small>a[i])
                small=a[i];
           }
           System.out.println("smallest no="+small);
     }
}
  
OUTPUT:


No comments :

Post a Comment