Computer Science, asked by Sneha23533, 8 months ago

Write a java program to accept the year of graduation from school as an integer value from the user. Using the Binary Search technique on the sorted array of integers given below,

Output the message "Record exists" If the value input is located in the array. If not, output the message "Record does not exist".

{1982, 1987, 1993, 1996, 1999, 2006, 2007, 2009, 2010}​

Answers

Answered by dipesh8051
18

ANSWER:

import java.io.*;

class Search{

int A[]={1982,1987,1993,1996,1999,2003,2006,2007,2009};

void display ()throwsIOException

{

BufferedReader br= new BufferedReader ( new InputStreamReader (System.in));

System.out.println("Enter year");

n= Integer.parseInt(br.readLine());

l=0;

h=A.length-1;

while(l<=h)

{

mid=(l+h)/2;

if(A[mid]==n)

{

flag=1;

break;

}

if(n>A[mid])

{

l=mid-1;

}

else if(n<A[mid])

{

h=mid-1;

}

}

if(flag==1)

{

System.out.println("Record exists");

}

else

{

System.out.println("Record does not exists");

}

}

}

Hope it helps...

MARK AS BRAINLIEST PLEASE

Similar questions