Create a free account on Computer Sir Ki Class and unlock access to valuable learning resources.
Exam Paper Downloads: After registering and logging in, you can download exam question papers in PDF format to practice and prepare for your exams.
Student Support: Get assistance with your doubts, queries, and questions related to your studies. Our support is here to help you understand topics and resolve your learning difficulties.
Register today and make your exam preparation easier and more effective!
import java.util.Scanner;
public class Search {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter year of graduation: ");
int graduationYear = scanner.nextInt();
int[] years = {1982, 1987, 1993, 1996, 1999, 2003, 2006, 2007, 2009, 2010};
boolean found = false;
int left = 0;
int right = years.length - 1;
while (left <= right) {
int middle = (left + right) / 2;
if (years[middle] == graduationYear) {
found = true;
break;
} else if (years[middle] < graduationYear) {
left = middle + 1;
} else {
right = middle - 1;
}
}
if (found) {
System.out.println("Record exists");
} else {
System.out.println("Record does not exist");
}
}
}
C. Sir| Created: 18-Apr-2019 | Updated: 18-Apr-2019|ICSE2014