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

Write about NESTING of METHODS in Java?

NESTING OF METHODS : A method of a class can be called only by an object of that class or [class itself in the case of static members] using the dot operator. However there is an e...

Difference Between Overriding & Over Loading in Java?

Difference between overriding & over loading: Method overriding is used to provide a different implementation for the same feature of the software it is code replacement. Method over loading...

Final variables and methods in Java

final variables and methods( ): All methods and variables can be overridden by default in subclass. If we wish to parent the sub classes from overriding the members of the super class, we can decl...

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