编辑代码

public class Main
{
    static int res=0;
    public static void main(String[] args)
    {
        String s1="FOSHSTS";
        String s2="FOSSTSS";
        test1(s1, s2);
        System.out.println(res);
    }
    public static void test1(String s1, String s2)
    {
        int[][] dp = new int[s1.length() + 1][s2.length() + 1];
        for (int i = 1 ; i <= s1.length() ; i++)
        {
            char char1 = s1.charAt(i - 1);
            for (int j = 1; j <= s2.length(); j++)
            {
                char char2 = s2.charAt(j - 1);
                if (char1 == char2)
                {
                    dp[i][j] = dp[i - 1][j - 1] + 1;
                    res=Math.max(res,dp[i][j]);
                } else {
                    dp[i][j] = 0;
                }
            }
        }
    }
}