You are on page 1of 1

import java.util.

Scanner;
class LinearSearch
{
public static void main(String args[])
{
int c,n, s;
Scanner sc = new Scanner(System.in);
System.out.println("Enter the numbers for search");
n = sc.nextInt();
int arr[] = new int[n];
System.out.println("Enter " + n + " integers");
for (c = 0; c < n; c++)
arr[c] = sc.nextInt();
System.out.println("Enter value to find");
s = sc.nextInt();
for (c = 0; c < n; c++)
{
if (arr[c] == s)
{
System.out.println(s + " is present at location " + (c + 1) + ".");
break;
}
}
if (c == n)
System.out.println(s + " is not present in array.");
}
}

You might also like