deepika deepi wrote:I hope you will understand why i am using if else in above.
Not really because, as usual, you haven't provided us with any context.
Your questions always seem to be of the form:
"I've written this code ... is it OK?"
And the answer (as it almost always will be in such a case) is:
It depends on what you're trying to do.
For the third time, I'm going to give you a few links on how to ask questions properly:
1.
HowToAskQuestionsOnJavaRanch.
2.
How to ask questions the smart way.
3. How to provide an
SSCCE.
and I strongly suggest that you read them; because, until you do, programming is likely to be a very frustrating experience for you -
and us.
Winston