32 lines
721 B
Java
32 lines
721 B
Java
import java.util.Scanner;
|
|
|
|
/**
|
|
* SequentialSearch
|
|
*/
|
|
public class SequentialSearch {
|
|
|
|
public static void main(String[] args) {
|
|
Scanner sc = new Scanner(System.in);
|
|
System.out.println("check the number x: ");
|
|
int input = sc.nextInt();
|
|
int[] arr = { 1, 3, 5, 6, 7, 21, 32, 42, 55, 66, 76, 83, 90 };
|
|
|
|
int position = 0;
|
|
boolean found = false;
|
|
|
|
while (position < arr.length && !found) {
|
|
if (arr[position] == input) {
|
|
found = true;
|
|
} else {
|
|
position = position + 1;
|
|
}
|
|
}
|
|
if (found) {
|
|
System.out.println(input + " found in position " + position);
|
|
} else {
|
|
System.out.println(input + " Not found in the array");
|
|
}
|
|
sc.close();
|
|
}
|
|
}
|