forked from Annex5061/java-algorithms
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathLinearSearch.java
33 lines (32 loc) · 970 Bytes
/
LinearSearch.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import java.util.*;
public class LinearSearch {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the element you want to search = ");
int Key = sc.nextInt();
int flag = 0;
int i =0;
int arr[] ={1,2,7,8};
// while(i<arr.length){
// if(arr[i]==number){
// System.out.println("Element found at index number " +i);
// break;
// }i++;
// }
// if(flag==1){
// System.out.println("Element found at index number" +i);
// }
// else{
// System.out.println("Element not found");
// }
while(i<arr.length && arr[i]!=Key){
i++;
}
if(i<arr.length){
System.out.println("jai ho");
}
else{
System.out.println("bhag bsdk");
}
}
}