you write the code that does so.
if your code fails, you post it here, and say what you're stuck with.
Prabhat_1: no doubt you meant well, but there are several reasons you shouldn't just post code here.
the rules each member here agreed on ( http://www.daniweb.com/community/rules ) requires us to (when we post a question) at least to provide some proof that we actually put in an effort for ourselves.
give the OP the chance to learn, not just to copy paste a "working" solution.
sure, this will work. but using Vector? (just a for instance).
your code is far from ideal. not only will the OP learn in a way that he literally just learns this code by heart, without truly understanding what it does, but he'll learn the flaws in the code as being "good code".
I'm sure you intended to help, but here we try to teach people the knowledge and skills they need. We don't just do their homework for them.
If you do want to post code here as an example or solution you should be careful that is is a good example, not just a load of uncommented unindented code based on an obsolete version of Java, otherwize you may find that it attracts a lot of criticism!