Showing posts with label Sequential Search. Show all posts
Showing posts with label Sequential Search. Show all posts

Friday, April 15, 2011

Sequential Search 2


import java.io.*;
class seqsearch
{
  public static void main(String args[]) throws IOException
  { searching x=new searching();
                DataInputStream in=new DataInputStream(System.in);
                int n=10,key=0;
                int a[]=new int[n];
                System.out.print("Enter number of elements ");
                n=Integer.parseInt(in.readLine());
               
                System.out.print("Enter elements");
               
                for(int i=0;i<n;i++)
                {
      a[i]=Integer.parseInt(in.readLine());
    }
   
    System.out.print("Enter number to be searched-");
   
    key=Integer.parseInt(in.readLine());
     
    int z=x.search(a,n,key);

Sequential Search 1


import java.io.*;
import java.util.*;
class seqsearch
{
public static void main(String arg[])
{    
      int a[]=new int[50];
      boolean flag=false;
                  DataInputStream in=new DataInputStream(System.in);
try{
                               
                    System.out.println("Enter the no of elements in d array");
                    int n=Integer.parseInt(in.readLine());
                    for(int i=0;i<n;i++)
                    {
                                  System.out.println("Enter the "+(i+1)+" element of d array");
                                  a[i]=Integer.parseInt(in.readLine());
                    }
                    System.out.println("Enter the element to be searched");
                    int num=Integer.parseInt(in.readLine());
                    for(int i=0;i<n;i++)
                    {
                                  if(a[i]==num)