Skip to content

Instantly share code, notes, and snippets.

@GammaBurst101
Created March 4, 2018 16:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GammaBurst101/795aecda28c31840dc153e5f1dcb4ac6 to your computer and use it in GitHub Desktop.
Save GammaBurst101/795aecda28c31840dc153e5f1dcb4ac6 to your computer and use it in GitHub Desktop.
This is the syntax of Linear Search algorithm in java.
import java.util.Scanner;
class LinearSearch
{
public static void main (String args[])
{
Scanner sc = new Scanner (System.in);
int arr[] = new int[10];
for (int j = 0;j<arr.length;j++)
{
arr[j] = sc.nextInt();
}
System.out.pritnln("Enter the integer to search for:");
int s = sc.nextInt();
for (int i = 0;i<arr.length;arr++)
{
if (arr[i] == s)
{
System.out.println ("Search found at : "+i);
break;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment