public static void main(String[] args) {
String input1;
String input2;
String n[]= new String [5];
int ID[]=new int [5];
int g[]=new int [5];
int c=1;
int id;
for(int i=0;i<5;i++)
{
input1=JOptionPane.showInputDialog("Enter the student name: ");
n=input1;
input2=JOptionPane.showInputDialog("Enter the grade: ");
g=Integer.parseInt(input2);
ID =100+i;
}
String i=JOptionPane.showInputDialog("Enter Student ID: ");
id=Integer.parseInt(i);
int found=binarySearch(ID,id);
JOptionPane.showMessageDialog(null,"Student name: "+n[id]+"\nSudent ID: "+ID[id]+"\nStudent grade: "+g[id]);
}
//Binary Search By Id
public static int binarySearch( int ID [ ] , int key )
{
int low = 0;
int high = ID.length - 1;
int mid;
while( low <= high )
{
mid = ( low + high ) / 2;
if( key>ID[mid] )
low = mid + 1;
else if(key<ID[mid] )
high = mid - 1;
else
return mid;
}
return -1; // NOT_FOUND = -1
}}

