MCPcopy Create free account
hub / github.com/PrajaktaSathe/Java / LinearSearch

Class LinearSearch

Programs/LinearSearch.java:1–25  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1class LinearSearch{
2
3 public static int search(int arr[], int x)
4 {
5 int n = arr.length;
6 for (int i = 0; i < n; i++)
7 {
8 if (arr[i] == x)
9 return i;
10 }
11 return -1;
12 }
13
14 public static void main(String args[])
15 {
16 int arr[] = { 45, 56, 37, 79, 46, 18, 90, 81, 51 };
17 int x = 79;
18
19 int result = search(arr, x);
20 if (result == -1)
21 System.out.print("\n\nElement is not present in array\n");
22 else
23 System.out.print("\n\nElement is present at index " + result + "\n");
24 }
25}
26

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected