if( i == -1){
if(a [0] == key){
return 0;
}else{
return -1;
}
}
if( i == -1){
if(a [0] == key){
return 0;
}else{
return -1;
}
}

see line number 15. that is responsible for getting the final answer.
for example->
1 2 3
let say u r looking for 2.
first u will make call on 1 , it will make call on 2 because 2 is required key we will return 0 to 1 .
at 1 we will add one to it and it will finally return 1,
so 1 is the required index we get