forked from FatimaAlazazi/DataStructure2021
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSequentialSearch.java
More file actions
42 lines (37 loc) · 1022 Bytes
/
SequentialSearch.java
File metadata and controls
42 lines (37 loc) · 1022 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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
Sepackage Week3;
import java.util.Scanner;
public class SequentialSearch {
static int [] a = {7,2,4,5,6,3,1};
static public void Print()
{
System.out.print("[ ");
for (int i = 0; i <a.length ; i++) {
if(i==a.length-1)
System.out.print(a[i]+" ]");
else
System.out.print(a[i]+" , ");
}
}
static public boolean Sequential_Sort(int element)
{
int x = -1 ;
int i = 0 ;
boolean f = false ;
while(!f && i<a.length)
{
if(a[i] == element)
{
f = true ;
x = i ;
}
i++;
}
return f;
}
public static void main(String[] args) {
System.out.println("Enter The Element : ");
Scanner in = new Scanner(System.in);
int x = in.nextInt();
System.out.println("The Result of Search : "+ Sequential_Sort(x));
}
}