-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinearSearch.java
More file actions
24 lines (22 loc) · 2.21 KB
/
Copy pathLinearSearch.java
File metadata and controls
24 lines (22 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import java.util.Random;
public class LinearSearch {
public static void main(String[] args) {
Random random = new Random();
int[] arr1 = {925, 699, 667, 139, 300, 408, 216, 326, 833, 557, 933, 636, 374, 822, 73, 856, 406, 440, 84, 170, 57, 7, 269, 862, 377, 590, 144, 717, 203, 375, 521, 914, 742, 74, 656, 690, 730, 68, 362, 516, 325, 930, 670, 232, 622, 733, 555, 532, 407, 146, 688, 637, 183, 301, 672, 456, 778, 715, 710, 96, 139, 690, 116, 162, 102, 434, 148, 862, 525, 458, 187, 160, 709, 252, 636, 735, 220, 741, 740, 171, 758, 195, 799, 456, 908, 831, 567, 211, 328, 662, 930, 126, 949, 273, 121, 80, 779, 344, 324, 371,40, 0, 95, 82, 11, 36, 18, 99, 68, 28, 89, 98, 30, 55, 80, 70, 57, 75, 27, 72, 15, 27, 60, 36, 81, 69, 91, 83, 44, 0, 44, 66, 68, 34, 14, 18, 49, 14, 29, 93, 21, 55, 35, 25, 58, 56, 77, 76, 68, 47, 17, 45, 72, 89, 80, 33, 64, 39, 12, 17, 36, 45, 7, 28, 38, 69, 47, 85, 22, 63, 95, 73, 20, 62, 28, 51, 82, 54, 14, 56, 63, 49, 86, 90, 26, 0, 76, 24, 57, 65, 86, 20, 53, 68, 91, 86, 87, 55, 78, 73, 13, 93, 59, 93, 11, 15, 52, 92, 22, 50, 82, 97, 3, 1, 87, 87, 45, 88, 4, 94, 48, 53, 60, 69, 77, 63, 84, 88, 55, 13, 31, 88, 84, 15, 49, 25, 86, 24, 51, 25, 66, 38, 97, 0, 59, 27, 60, 12, 53, 88, 1, 42, 76, 81, 72, 70, 55, 28, 66, 69, 85, 95, 53, 81, 30, 98, 57, 59, 92, 14, 24, 0, 55, 25, 40, 29, 32, 42, 37, 30, 74, 20, 26, 25, 89, 43, 4, 93, 6, 35, 94, 98, 5, 45, 37, 68, 99, 44, 12, 41, 14, 33, 68, 63, 71, 92, 97, 7, 45, 48, 37, 87, 35, 49, 59, 95, 76, 60, 13, 41, 24, 15, 3, 86, 8, 71, 55, 49, 39, 60, 60, 43, 36, 81, 87, 21, 35, 2, 26, 15, 23, 59, 2, 73, 18, 54, 37, 76, 45, 40, 35, 14, 4, 12, 41, 55, 14, 25, 79, 69, 14, 59, 48, 31, 61, 66, 45, 70, 12, 3, 63, 96, 45, 77, 54, 83, 34, 83, 78, 95, 15, 75, 38, 60, 74, 79, 4, 39, 82, 23, 20, 34, 88, 60, 13, 7, 81, 72, 38, 66};
// System.out.println(Arrays.toString(arr1));
int item = 55;
int result = search(arr1,item);
System.out.println(result);
}
private static int search(int[] arr, int item) {
if (arr == null) {
return -1;
}
for (int i = 0; i < arr.length; i++) {
if (item == arr[i]) {
return i;
}
}
return -1;
}
}