If mid is equal i , check mid - 1 and mid + 1
if ( mid == i ) { if ( ( mid - 1 >= 0 ) && nums [ mid - 1 ] == x ) { System . out . print ( nums [ i ] + " , ▁ " ) ; System . out . print ( nums [ mid - 1 ] ) ; return ; } if ( ( mid + 1 < n ) && nums [ mid + 1 ] == x ) { System . out . print ( nums [ i ] + " , ▁ " ) ; System . out . print ( nums [ mid + 1 ] ) ; return ; } break ; }