-
-
Save GammaBurst101/795aecda28c31840dc153e5f1dcb4ac6 to your computer and use it in GitHub Desktop.
This is the syntax of Linear Search algorithm in java.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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