Java Code - Comparing last 4 letters -


implement method returns true if final 4 character substrings of s1 , s2 equal. if length of either string less 4, method should return false.

you may use method s.substring(n, m) yields substring of s beginning @ index n , ending @ index m-1.

as answer delivered following code, wondering whether did in correct way:

public static boolean comparelast4 (string s1, string s2) {     s1len = s1.length;     s2len = s2.length;     if (s1lan < 4 || s2len < 4)         return false;     (int = 0; < s1len; i++)         if (s1.substring() - 4.equals(s2.length() - 4))             return true;         return false; } 

i'd like:

public static boolean comparelast4 (string s1, string s2)  {     if (s1.length() < 4 || s2.length() < 4)         return false;     return s1.substring(s1.length() - 4).equals(s2.substring(s2.length()-4)); } 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -