Linear Search In Java
package sorting;
import java.util.Scanner;
public class LinearSearch {
public static void main(String[] args) {
int arr[] = { 1, 2, 3, 8, 5, 6, 1 };
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
for (int i : arr) {
if (i == num) {
System.out.println("Found the number " + i);
break;
}
}
sc.close();
}
}
Comments
Post a Comment