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

Popular posts from this blog

3 Lines of Code And You Can Download Your Favourite Youtube Video.

Leetcode Problem(Easy) Roman to Integer

Leetcode : (Find Minimum in Rotated Sorted Array)