PROGRAM TO FIND MINMUM AND MAXIMUM ELEMENT IN AN ARRAY

//PROGRAM TO FIND MINMUM AND MAXIMUM ELEMENT IN AN ARRAY
class minMax
{
public static void main(String args[ ])
{
int a[ ]={2,43,1,5,9,5,22,11,10};
int min,max,i,j;
System.out.println(“Elements of array are : “);
for(i=0;i<a.length;i++)
{
System.out.print(a[i]+”\t”);
}
System.out.println(“”);
min=a[0];
for(i=0;i<a.length;i++)         //SEARCHING MINIMUM ELEMENT
{
if(min>a[i])
{
min=a[i];
}
}
System.out.println(“Minimum element in array is: “+min);
max=a[0];

for(i=0;i<a.length;i++)        //SEARCHING MAXIMUM ELEMENT
{
if(max<a[i])
{
max=a[i];
}
}
System.out.println(“Maximum element in array is: “+max);
}
}

Leave a Reply

Your email address will not be published. Required fields are marked *