Put the last element back
arr [ n - 1 ] = last ; if ( ( i < n - 1 ) || ( arr [ n - 1 ] == key ) ) System . out . println ( key + " ▁ is ▁ present ▁ at ▁ index ▁ " + i ) ; else System . out . println ( " Element ▁ Not ▁ found " ) ; }