0% found this document useful (0 votes)
4 views2 pages

Java Linear Search Implementation

The document contains a Java program that implements a linear search algorithm. It initializes an array of integers and includes methods for accepting user input and printing the search results. However, there are errors in the code, such as incorrect array indexing and missing functionality for the search process.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

Java Linear Search Implementation

The document contains a Java program that implements a linear search algorithm. It initializes an array of integers and includes methods for accepting user input and printing the search results. However, there are errors in the code, such as incorrect array indexing and missing functionality for the search process.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

import [Link].

*;

class linearsearch

//instance variables

static int arr[];

linearsearch()

arr = new int[7];

public static void main(String args[])

int pos=0;

boolean isfound= false;

Scanner sc=new Scanner([Link]);

print(pos, isfound);

static void accept()

Scanner sc= new Scanner([Link]);

int val;

for(int i=0;i<=[Link];i++)

[Link]("ENTER NUMBERS");

arr[i]=[Link]();
}

static void checker()

for(int i=0;i<=[Link];i++)

[Link]("arr["+(i)+"[="+arr[i]);

static void print(int pos, boolean isfound)

if(isfound)

[Link]("Value found at position"+(pos+1));

You might also like