Skip to content
This repository was archived by the owner on Jun 2, 2024. It is now read-only.

Commit 0893229

Browse files
Update binarySearchR.java (#876)
* Update binarySearchR.java * Update binarySearchR.java * add some lines Co-authored-by: VanshikaSharma <85174042+Vanshika2063@users.noreply.github.com>
1 parent 5742df0 commit 0893229

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

Java/Algorithm/SearchingAlgorithm/binarySearchR.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
1+
import java.util.Scanner;
12
public class binarySearchR {
23
public static void main(String[] args) {
3-
int[] arr= {2, 4, 5, 6,8, 9, 10,23,26, 29};
4-
int target= 4;
5-
System.out.println(search(arr, target, 0, arr.length-1));
4+
5+
Scanner sc = new Scanner(System.in);
6+
7+
System.out.print("define your array size: ");
8+
int n = sc.nextInt();
9+
10+
int arr[] = new int[n];
11+
12+
for(int i=0; i<n; i++)
13+
arr[i] = sc.nextInt();
14+
15+
System.out.println("your target is: ");
16+
int target= sc.nextInt();
17+
18+
System.out.println(search(arr, target, 0, n-1));
619
}
720
static int search(int[] arr, int target, int start, int end){
821
if (start>end){

0 commit comments

Comments
 (0)