import java.util.Scanner;
public class RansariLinearSearch {
public static void main(String args[]) {
Scanner in = new Scanner(System.in); // Create Scanner object for input
double arr[] = new double[20]; // Declare an array of double data type with size 20
int l = arr.length; // Get the length of the array (which is 20)
int i = 0;
// Accept values for the array from the user
System.out.println("Enter array elements: ");
for (i = 0; i < l; i++) {
arr[i] = in.nextDouble(); // Accept each double value from the user and store it in the array
}
// Ask user for the number to search in the array
System.out.print("Enter the number to search: ");
double n = in.nextDouble(); // Accept the number to search for
// Linear search algorithm
for (i = 0; i < l; i++) {
if (arr[i] == n) { // If the current element is equal to the number being searched
break; // Exit the loop when the value is found
}
}
// Check if the number was found or not
if (i == l) {
System.out.println("Not found"); // If the loop goes through all elements and doesn't find the number
} else {
System.out.println(n + " found at index " + i); // If the number was found, display the index
}
in.close(); // Close the Scanner object
}
}