Longest Common Substrings - a Java code sample
Description
This is a short program to find the longest common substrings in two strings. There is also an option to print out all of the common substrings.Raison d'être
My friend Louise has a job at Morgan Stanley. They've given her a bunch of exercises to do before she starts work. This was one of them.From: Louise
To: Brian
I wrote a program yesterday that finds the longest common substring in 2 strings for MS. It's not as easy as you think!
From: Brian
To: Louise
Sounds like an interesting challenge - I'll have a look at it later, if I remember!
From: Brian
To: Louise
Ok, what's next? :)
Writing the args[] handling code took longer than the actual method!
Development Plans
Development has finished.Development History
23/07/08 - Louise mentioned the exercise to me24/07/08 - I did it.
System Requirements
- Java Runtime Environment, version 5 or above
- Any Windows, Mac or Linux operating system *should* work
Downloads
CommonSubstrings.javaInstructions
Download the file linked above to and open it in a text editor.To compile the program, run "javac CommonSubstrings.java" from a command prompt in the same directory as the file. You will need the Java SDK installed for this to work.
To run the program, run the command "java CommonSubstrings $arg1 $arg2 $arg3" from a command prompt in the same directory as the compiled .class file. $arg1, $arg2 and $arg3 are arguments to the program. It needs two Strings, (e.g. java CommonSubstring "test" "teest") to be able to function. The third argument (which can be in any position) is an optional "-v". If this is found, verbose output will be on and the program will output all of the common substrings as well as the longest.
Licence
I don't currently have a specific licence in mind at the moment. However, the conditions I want you to abide by are these:- I am not responsible for anything that goes wrong with your computer, either as a result of using this program or not.
- The program has absolutely no guarantee of quality or anything of the sort. It is provided free of charge for entertainment purposes. You should not use this program on any computer where security, uptime or quality of service are important. If you do, and something goes wrong, then you agree to acknowledge that the program was not my fault in any way, and in fact was your fault for messing around on important machines.
- You are welcome to distribute this program as much as you want, as long a) as you do so without charge, and b) You do not remove any references to me as the creator.
In other words, please feel free to give it to your friends, don't take money in exchange for it and don't claim that it's your work. - If you want to alter the program, feel free. If you want to share your alterations with other people, then you may do so as long as a) you don't charge for them, and b) you don't remove any references to me as the original creator.
In other words, the source code is available for you to use - please use it if you want to! If you create something nice, then share nicely and don't make other people pay for it. Also, don't claim that it's entirely your work if it isn't.