Problem in my approach?

after writting the condition in if() block why the output is not same

please reply to my query