JAVA PROGRAM FOR LINEAR SEARCH

import java.io.*; class Search {             public static void main(String args[ ])throws IOException             { BufferedRea...

import java.io.*;
class Search
{
            public static void main(String args[ ])throws IOException
            {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
                         System.out.println("ENTER N VALUE");
                         int n=Integer.parseInt(br.readLine( ));
                         int a[ ]=new int[n];
                         for (int i=0;i
                        {
                                    System.out.println("ENTER ELEMENT");
                                    a[i]=Integer.parseInt(br.readLine( ));
                        }
                         int found=0;
                         System.out.println("ENTER KEY VALUE");
                         int key=Integer.parseInt(br.readLine());
                         for(int i=0;i
                                    {
                                                 if(key==a[i])
                                                            {
                                                                        found=1;
System.out.println("KEY IS FOUND AT"+i);
                                                                         break;
                                                             }
                                    }
                                    if(found==0)
                                    {          
System.out.println("KEY IS NOT FOUND");
                                    }
                                   
                        }
}



OUTPUT:

ENTER N VALUE
5
ENTER ELEMENT
1
ENTER ELEMENT
2
ENTER ELEMENT
3
ENTER ELEMENT
4
ENTER ELEMENT
5
ENTER KEY VALUE
4
KEY IS FOUND AT 3




Related

How to add a new Class to a Package?

Adding a class to a package: It is simple to add a class to an existing  package.consider the following package. package p1; public classA { Body of A } The package p1 contains one p...

How to Create and Access Packages in Java?

Creating Packages: We must first declare the name of the package keyword followed by a program name. This must be the first statement in a Java source file(except for comments and  white space...

What is a Package? What are its Uses?

Package: One of the main feature of OOP is its ability to re use the code the code already created. One way of achieving this is by extending the classes and implementing the Interfaces. If ...

Post a Comment

emo-but-icon
:noprob:
:smile:
:shy:
:trope:
:sneered:
:happy:
:escort:
:rapt:
:love:
:heart:
:angry:
:hate:
:sad:
:sigh:
:disappointed:
:cry:
:fear:
:surprise:
:unbelieve:
:shit:
:like:
:dislike:
:clap:
:cuff:
:fist:
:ok:
:file:
:link:
:place:
:contact:

item