forked from pikachu-17/java-projects
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path03.java
More file actions
37 lines (28 loc) · 866 Bytes
/
03.java
File metadata and controls
37 lines (28 loc) · 866 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
import java.util.*;
public class binary
{
public static void main()
{
Scanner sc=new Scanner(System.in);
int years[]={2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010};
int start=0;
int end=years.length-1;
System.out.println("Enter the year to be searched");
int y=sc.nextInt();
while(end>=start)
{
int mid=(start+end)/2;
if(years[mid]==y)
{
System.out.println("it is present at the location");
break;
}
else if(years[mid]>=y)
end=end-1;
else if(years[mid]<=y)
start=start+1;
}
if(start<end)
System.out.println("Record does not exist");
}
}