PROGRAM TO SEARCH AN ELEMENT IN A GIVEN ARRAY

//PROGRAM TO SEARCH AN ELEMENT IN A GIVEN ARRAY
class searchArray
{
public static void main(String args[ ])
{
int a[ ]={3,6,8,9},d,f=0,i,c=0;
d=9;
System.out.println(“Elements in the array are: 3,6,8,9″);
System.out.println(“Element to be search is 9″);
for(i=0;i<=3;i++)
{
if(d==a[i])
{
f=1;
c=i+1;
}
}
if(f==1)
{
System.out.println(“Element is present at location:”+c);
}
}
}

Leave a Reply

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