Skip to content

Commit cd0d3ef

Browse files
authored
Binary Search div-bargali#533
Binary Search
2 parents 2b0da11 + 35f9961 commit cd0d3ef

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import java.util.Scanner;
2+
3+
public class searching {
4+
public static void main (String [] arhs) {
5+
Scanner sc = new Scanner(System.in);
6+
System.out.print("Enter size of array = ");
7+
int n = sc.nextInt();
8+
String a [] = new String[n];
9+
String b [] = new String[n];
10+
11+
System.out.print("Enter values of A string : ");
12+
13+
for (int k =0; k<a.length; k++) {
14+
a[k] = sc.next();
15+
}
16+
System.out.print("Enter values of B string : ");
17+
for (int k =0; k<b.length; k++) {
18+
b[k] = sc.next();
19+
}
20+
21+
int result = match(a,b);
22+
23+
System.out.println(result + " words found to be same" );
24+
}
25+
26+
static int match (String a[], String b[]) {
27+
int s =0;
28+
for (int i =0; i<a.length; i++) {
29+
for (int j=0; j<b.length; j++) {
30+
if (a[i] == " ")
31+
break;
32+
else if (a[i].equals(b[j]))
33+
s = s+1;
34+
}
35+
}
36+
return s;
37+
}
38+
}

0 commit comments

Comments
 (0)