Skip to content

Instantly share code, notes, and snippets.

@iamrajendra
Created January 14, 2021 18:25
Show Gist options
  • Save iamrajendra/13b0f9f12a033b9ec87f7460bde35748 to your computer and use it in GitHub Desktop.
Save iamrajendra/13b0f9f12a033b9ec87f7460bde35748 to your computer and use it in GitHub Desktop.
private static int linearSearch() {
int arr[] = new int[]{10, 20, 80, 30, 60, 50, 110, 100, 130, 170};
int x = 110;
for (int i = 0; i < arr.length; i++) {
if (x == arr[i]) return i;
}
return -1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment