Note that this question is case-insensitive. Therefore, you must convert the input string to lowercase or uppercase before computation.
Second, the idea must be clear. First, match S1 WITH S2 [J] Starting from [I]. If S1 is not equal, J ++ continues until J is equal to s2.length () -1, equal, then I ++, J ++. Note: here is I ++, that is, the distance between the two I may exceed 1 when the matching starts from S [I] again next time. Set a counter in J.
Import Java. util. optional; public class findmaxsubstringlength {public static int getcommonstrlength (string S1, string S2) {int COUNT = 0; If (S1 = "" | S2 = "") return 0; For (INT I = 0; I <s1.length (); I ++) {for (Int J = 0; j <s2.length (); j ++) {int number = 0; if (I = s1.length () | j = s2.length () {break;} while (s1.charat (I) = s2.charat (j )) {I ++; j ++; number ++; Count = count> Number? Count: Number; if (I = s1.length () | j = s2.length () {break;} If (COUNT = s1.length () | COUNT = s2.length () return count ;}} return count;} public static void main (string ARGs []) {empty input = new partition (system. in); string S1 = input. next (); string S2 = input. next (); S1 = s1.tolowercase (); S2 = s2.tolowercase (); system. out. println (getcommonstrlength (S1, S2 ));}}