Java program to search an item into the array using linear search
All Answers
total answers (1)
Severity: 8192
Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated
Filename: libraries/Filtered_db.php
Line Number: 23
total answers (1)
In this program, we will create an array of integers then we will search an item into the array using linear search and print position of the item in the array.
The linear searching algorithm is used to find the item in an array, This algorithm consists the checking every item in the array until the required item is found or till the last item is in the array. The linear search algorithm is also known as a sequential algorithm.
Program/Source Code:
The source code to search an item into the array using linear search is given below. The given program is compiled and executed successfully.
Output:
Explanation:
In the above program, we imported the java.util.Scanner package to read the variable's value from the user. And, created a public class Main. It contains two static methods linearSearch() and main().
The linearSearch() method is used to search an item into the array and return the index of the index to the calling method.