• Print Common Suffix In…

     Akash  updated 10 months, 2 weeks ago 2 Members · 2 Posts
  • Akash 

    Administrator
    at

    Print Common Suffix In Strings

    Ex: cornfiled , Exfiled — field

  • Akash 

    Administrator
    at

    class Main

    {

    public static void main (String[]args)

    {

    String s1 = “cornfiled”;

    String s2 = “Exfiled”;

    String suffix;

    if (s1.length () > s2.length ())

    {

    suffix = searchSuffix (s1, s2);

    }

    else

    {

    suffix = searchSuffix (s2, s1);

    }

    System.out.println (“Matching suffix is :” + suffix);

    }

    static String searchSuffix (String searchString, String searchInString)

    {

    String sbSearch = null;

    for (int i = 0; i < searchString.length (); i++)

    {

    sbSearch = searchString.substring (i);

    System.out.println (“sbSearch :” + sbSearch);

    if (searchInString.contains (sbSearch))

    {

    return sbSearch;

    }

    }

    return null;

    }

    }

Log in to reply.

Original Post
0 of 0 posts June 2018
Now
KodNest Training New Batch is starting on 5th October 2020. Attend one week free demo classes.Register Now

New Report

Close