27 lines
561 B
Java
27 lines
561 B
Java
/**
|
|
* SequentialSearchSortedarray
|
|
*/
|
|
public class SequentialSearchSortedarray {
|
|
|
|
public static void main(String[] args) {
|
|
int[] sortedArray = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
|
|
int index = SeqSearch(sortedArray, 53);
|
|
if (index != -1) {
|
|
System.out.println("Element found at index " + index);
|
|
} else {
|
|
System.out.println("Element not found");
|
|
}
|
|
|
|
}
|
|
|
|
public static int SeqSearch(int[] arr, int value) {
|
|
for (int i = 0; i < arr.length; i++) {
|
|
if (arr[i] == value) {
|
|
return i;
|
|
}
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
}
|