package org.santhoshkumar;

import  java.util.Scanner;

public class LongestCommonSubSequence {

    public static void main(String[] args) {
        Scanner sc  = new Scanner(System.in);

        String one = sc.nextLine();
        String two = sc.nextLine();

        LongestCommonSubSequence lcs = new LongestCommonSubSequence();
        //lcs.findSolution("santhoshkumar","santosh");
        lcs.findSolution(one,two);
    }

    public void findSolution(String one, String two){
        int cols = one.length();
        int rows = two.length();
        char[] strOne = one.toCharArray();
        char[] strTwo = two.toCharArray();

        int matrix[][] = new int[rows+1][cols+1];
        // Initialize the columns to 0, meaning if string is null result is 0, no common subsequence
        for(int i=0; i <= cols; i++){
            matrix[0][i] = 0;
        }

        for(int j=0; j <=rows; j++){
            matrix[j][0] = 0;
        }

        for(int i =1; i<=rows; i++){
            for(int j =1; j<=cols; j++){
                System.out.print(matrix[i][j]+" ");
            }
            System.out.println();
        }

        for(int i =1; i<=rows; i++){
            for(int j =1; j<=cols; j++){
                if(strOne[j-1] == strTwo[i-1]){
                    matrix[i][j] = matrix[i-1][j-1]+1;
                }else{
                    matrix[i][j] = Math.max(matrix[i-1][j],matrix[i][j-1]);
                }
            }
        }
    }
}

@@ -1445,20 +1445,582 @@
 %7D%0A        %7D%0A
+        %0A        // Following code is used to print LCS%0A        int index = matrix%5Brows%5D%5Bcols%5D;%0A        // Create a character array to store the lcs string%0A        char%5B%5D lcs = new char%5Bindex%5D;%0A        index--;%0A        int i = rows, j = cols;%0A        while (i %3E 0 && j %3E 0)%0A        %7B%0A            if (strOne%5Bj-1%5D == strTwo%5Bi-1%5D)%0A            %7B%0A                lcs%5Bindex--%5D = strTwo%5Bi-1%5D;%0A                i--; j--;%0A            %7Delse if (matrix%5Bi-1%5D%5Bj%5D %3E matrix%5Bi%5D%5Bj-1%5D)%7B%0A                i--;%0A            %7Delse%7B%0A                j--;%0A            %7D%0A        %7D%0A        %0A
     %7D%0A%7D%0A

Update LongestCommonSubSequence.java