Sunday, November 4, 2012

Java Exercise #43: Common Prefix

Write a method that returns the common prefix for two strings. For example, the common prefix for "distance" and "disappoint" is "dis". If the strings don't have a common prefix, print there is no common prefix between them.

Exercise: Write a program that prompts the user to enter two strings and display their common prefix.


Enter first string: paddy
Enter second string: wheat
No common prefix!

Enter first string: Display
Enter second string: disappoint
Common prefix is : dis


Download Code: Common Prefix

No comments:

Post a Comment