-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathSearch.java
More file actions
49 lines (45 loc) · 1.24 KB
/
Search.java
File metadata and controls
49 lines (45 loc) · 1.24 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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author hp
*/
class Lsearch {
boolean linearsearch(int a[],int keynum){
boolean found=false;
for(int i=0;i<10;i++){
if(a[i]==keynum){
found=true;
}
}
if (found==true) System.out.println("found");
else
System.out.println("not found");
return found;
}
boolean linearsearch(char b[],int keychar){
boolean found=false;
for(int i=0;i<10;i++){
if(b[i]==keychar){
found=true;
}
}
if (found==true) System.out.println("found");
else
System.out.println("not found");
return found;
}
}
public class Search{
public static void main(String args[]){
Lsearch s=new Lsearch();
int a[]={1,5,7,0,3,10,12,11,31,2};
char b[]={'a','r','t','3','6','w','f','y','k','h'};
int keynum=0, keychar='a' ;
s.linearsearch(b, keychar);
s.linearsearch(a, keynum);
}
}