The following code is designed to compare 2 files to see if there is a sign of plagiarism. The code works, but I was wondering if there a way to memorize or make the code run faster. Here I'm only talking about the lcslength() and plagiarismChecker() functions.public class PlagiarismChecker {int lcsLength = 0;                        // lcsLength: will hold lcs  size to be used later for printingstatic double holdPlagScore = 0.0;       // holdPlagScore: will hold the Plagiarism score to be used whenever neededstatic String[] filenames = new String[2];          // filenames: is an array that holds both files in the arraystatic String[] filecontents = new String[2];     // filecontents: is an array that holds the String of word from// each file given// compares 2 sent in programs to check if there is a sign of plagiarismpublic static void main(String[] args) {    String prog1;    String prog2;    try {        PlagiarismChecker plgCkr = new PlagiarismChecker();        // use files if on your system        if (args.length < 1) {            filenames[0] = pl1.rtf;            // prog1: holds all the words from in the file as a string            prog1 = plgCkr.fileWriter(filenames[0]);            // filecontents: puts all of the words from the file to lowerCase for later comparison            filecontents[0] = prog1.toLowerCase();            filenames[1] = pl2.rtf;            // prog2: holds all the words from in the file as a string            prog2 = plgCkr.fileWriter(filenames[1]);            // puts all of the words from the file to lowerCase for later comparison            filecontents[1] = prog2.toLowerCase();            // using terminal            } else {            filenames[0] = args[0];            // prog1: holds all the words from in the file as a string            prog1 = plgCkr.fileWriter(filenames[0]);            // filecontents: puts all of the words from the file to lowerCase for later comparison            filecontents[0] = prog1.toLowerCase();            filenames[1] = args[1];            prog2 = plgCkr.fileWriter(filenames[1]);            // filecontents: puts all of the words from the file to lowerCase for later comparison            filecontents[1] = prog2.toLowerCase();        }        plgCkr.lcsLength(prog1, prog2);        plgCkr.plagiarismChecker(filenames, 46);       } catch (Exception e) {        System.out.println(Error:  + e.getMessage());      }   }// The fileWriter() takes in the name of the file sent in (which is a string) and puts all the contents from the file// into a string and then it returns that string to be used by other methods.public String fileWriter(String fileName) throws IOException {    // fin: turns the string sent to a RandomAccessFile    RandomAccessFile fin = new RandomAccessFile(fileName, r);    int b = (int) fin.read();   // b: int at that spot in the file to be converted to a char    String fContents = ;      // fContents: words in file stored as 1 string    while (b != -1) {   // while there is another character continue...        char c = (char)b;   // make the int at that spot in the file a char        fContents = fContents + c;  // add new char to the string        b = (int) fin.read();   // next char spot    }    fin.close();    // test to see contents of file    //System.out.println(file:  + fContents);    //System.out.println(next);    return fContents;} //lcsLength() is designed to take in 2 strings which is just a string for each file and has all its contents in the// string. Then it sends the combined min. length back as a int.public int lcsLength(String prog1, String prog2) {    int n = prog1.length();    int m = prog2.length();    int[][] L = new int[n + 1][m + 1];    // Filling    for (int i = 0; i < n; i++) {        for (int j = 0; j < m; j++) {            // Align the match            if (prog1.charAt(i) == prog2.charAt(j)) {                L[i + 1][j + 1] = L[i][j] + 1;                // choose to ignore 1 character i.e. no match and take the max            } else {                L[i + 1][j + 1] = Math.max(L[i][j + 1], L[i + 1][j]);            }        }    }    lcsLength = L[n][m] - 1;  // store the lcs size to be printed if we cant have it in the main    return L[n][m];         // return the lcs answer.}// plagiarismChecker() does a pairwise comparison of the 2 files from the array and the method prints a// neatly formatted report listing any suspicious pairs.  The report includes their// plagiarism score aswell.public void plagiarismChecker(String[] filenames, double threshold) throws IOException {    // suspicious: holds the string of characters that were suspiciously identical    String suspicious = ;    // C: the character from the file string.    char c;    // holds the number of identical pairs from the 2 files    int pairCounter = 0;    double pScore = plagiarismScore(filecontents[0], filecontents[1]);    // smallFile: run through the smaller file to compare against bc it will have less characters in the file.    int smallerFile = Math.min(filecontents[0].length(), filecontents[1].length());    // checking for identical pairs    for (int i = 0; i < smallerFile; i++) {        // get characters from smaller file        if (smallerFile == filecontents[0].length()) {            c = filecontents[0].charAt(i);        }        // other file must have been smaller so get its characters.        else {            c = filecontents[1].charAt(i);        }        // looking for matches        if (!(filecontents[0].charAt(i) == filecontents[1].charAt(i))) {            suspicious = suspicious + c;    // add all suspicious characters to make a string            pairCounter++;  // add to count of suspicious matches        }    }    // print out the files and the score between them    System.out.println(File 1  File 2  Score: );    System.out.print(filenames[0] +     + filenames[1] +     );    System.out.printf(%.2f, holdPlagScore);    System.out.println();    // Print out pairs of plagiarism if it was found    if ((!(pScore < threshold)) && suspicious.length() > 0) {        System.out.println();        System.out.println(Score was higher than threshold Value    Plagiarism detected);        System.out.println(Suspicious pairs: \n);        System.out.println(suspicious);        System.out.println();        // no pairs were detected    } else {        System.out.println();        System.out.println(No Plagiarism was Detected score was less than Threshold Value );        System.out.println();    }}// plagiarismScore() is designed to calculate the plagiarism score for the two files. This will be done by calling// the lcsLength() and by using DR. Hansen's formulapublic double plagiarismScore(String filename1, String filename2) {    double num = ((double) 200 ) * lcsLength(filename1, filename2);    double dem = filename1.length() + filename2.length();    double pScore = num / dem;    System.out.println(The LCS Length between the 2 files:  +  lcsLength + \n);    holdPlagScore = pScore;    return pScore;  }}
Comparing files for plagiarism
java