This sounds to me like a basic undergraduate level computer science assignment.
If it is, then you will probably have a lab class that goes along with the lecture portion.
In the lab class the instructor (probably a grad student) will give you algorithms and insight on how to design your application. He will probably be your best source of information. We will be a good source of information when you get stuck in some of the coding.
The String class represents character strings. All string literals in Java programs, such as "prasad", are implemented as instances of this class.
Strings are constant; their values cannot be changed after they are created. String buffers support mutable strings. Because String objects are immutable they can be shared. For example:
String str = "prasad";
This creats a string literal, sets it's contents to "prasad" and pases the reference to that literal back to your variable [str].
String str = new str("prasad");
creates a string literal and sets contents to "prasad" (just like above). But a new string is created and the reference to that literal is passed to it. THEN that new string's referenc is passed to your variable [str].
Since TWO string literals are created in the second example, use the first one in your programs.