Wednesday, January 16, 2008

Search[Array]

WAP to find a particular element is a array and Display its position in the array

import java.io.*;
class PositionSearch
{
public static void main(String args[])throws IOException
{
int x[]=new int[10];
int a=0,i=0,j=0;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println(" Enter 10 Values");
for(i=0;i<10;i++)
{
x[i]=Integer.parseInt(br.readLine());
}
System.out.println(" Enter the Value u want to search ");
int n=Integer.parseInt(br.readLine());
for(i=0;i<10;i++)
{
if(x[i]==n)
System.out.println(" the desired element is present at position " + i );
}
}
}

No comments: