Title

JAVA

      In this blog, you will find programs on JAVA and also some help on how to write programs for JAVA...

December 18, 2014

Sequential Search

import java.util.Scanner;

public class SSearch
{
    public static void main()
    {
        Scanner s=new Scanner(System.in);
        System.out.print("Enter the no you want to search: ");
        int n=s.nextInt();
        int m[]={12,45,34,23,1,3,2,7,98};
        boolean found=false;
        for(int x=0; x<m.length; x++)
        {
            if(m[x]==n)
            {
                found=true;
                break;
            }
        }
        if(found==true)
            System.out.println("Found");
            else
            System.out.println("Not Found");
    }
}

No comments:

Post a Comment

Please write your comment in the box below...