forked from 790hanu/Annex-qr-code-simulator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinearSearch.java
More file actions
27 lines (23 loc) · 732 Bytes
/
LinearSearch.java
File metadata and controls
27 lines (23 loc) · 732 Bytes
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
import java.util.Scanner;
public class LinearSearch {
public static void main(String[] args) {
int i, num, pos = 0;
int[] arr = new int[10];
Scanner s = new Scanner(System.in);
System.out.print("Enter 10 Elements: ");
for (i = 0; i < 10; i++)
arr[i] = s.nextInt();
System.out.print("Enter an Element to Search: ");
num = s.nextInt();
for (i = 0; i < 10; i++) {
if (num == arr[i]) {
pos = i + 1;
break;
}
}
if (pos == 0)
System.out.println("\nThe element not found!");
else
System.out.println("\nThe element found at position: " + pos);
}
}