Java Tutorial

 
 
 
 

Image

import java.io.*;

class search
{
      String str;
      int key,size,seaArr[];

      public void getdata()
      {
             System.out.print(\"Enter how many data you want to enter : \");
             System.out.flush();
             try{
                 BufferedReader obj=new BufferedReader(new 

InputStreamReader(System.in));
                 str=obj.readLine();
                 size=Integer.parseInt(str);
                 seaArr=new int[size];
                 for(int i=0;i<size;i++)
                   {
                       System.out.print(\"Enter element at \"+(i+1)+\"th 

position  :  \");
                       System.out.flush();
                       str=obj.readLine();
                       seaArr[i]=Integer.parseInt(str);
                   }
                }
            catch(Exception e)  {}
      }

      public int LinSrch()
      {
            System.out.println(\"=====LINEAR SEARCH=====\\n\");
            getdata();
            System.out.print(\"\\nEnter Search Key : \");
            System.out.flush();
            try{
              BufferedReader obj=new BufferedReader(new InputStreamReader

(System.in));
              str=obj.readLine();
              key=Integer.parseInt(str);
                for(int i=0;i<size;i++)
                    {
                          if(seaArr[i]==key)
                               return(i+1);
                     }
                 }
             catch(Exception e) {}
             return(0);
        }    
}

class  linSea
{
    public static void main(String args[]) 
    {
           search o1 = new search();
           int result;
           result=o1.LinSrch();
           if(result==0)
                 System.out.println(\"\\nSearch Not Found\");
            else
                 System.out.println(\"\\nSearch is Located at \"+result+\" 

Position\");
    }
}

    Related Post:
  1. Program to show an example of Copying i.e. Clonning Objects

  2. RMI based application for login validation based on data saved in text file stored on the server and will display appropriate message to the client..

  3. Program of writing Bytes to a File

  4. Program to show the comparing of Strings for equality

  5. File Handling- JAVA

  6. Program to declare, initialize and print an array of integers

  7. Word list program that reads a text file and makes an alphabetical list of all the words in that file. The list of words is output to another file

  8. An applet program of showing new document using showDocument(URL) method

  9. Program to show an example of Arrays of String

  10. Pass the marks of 10 students from the client side design a servlet, which takes these marks and returns the number of students who obtained first cls

  11. Corba program to encrypt the text that you want to send on the client side. The server side decrypts it after receiving. Append server time.

  12. Program to generate Fibonacci Series of a given number

  13. Program to show the use of If Statement

  14. An applet program to find maximum of three numbers using textField

  15. Program to read input from the Standard Input Device

  16. Write a program for restaurant

  17. Create an interface coversions. Which have the following functions Inchestomillimeters(), hptowatts(),wattstohp(),poundstogram(),gramtopounds()

  18. Program to calculate the frequency for different values of C starting from 0.01 to 0.1 in steps of 0.01

  19. Program that will read real number from the keyboard and print the following output in one line: small Integer not less The Given Number Largest Int

  20. Corba program to Write a Echo server and client with UDP server and client

 
 
Didn't find what you were looking for? Find more on Program of linear search