Search:

Type: Posts; User: helloworld922

Search: Search took 0.10 seconds.

  1. Replies
    13
    Views
    5,140

    Re: First string is a substring of another

    subVirus? :D I merged your two topics and marked the original one as un-solved.

    Oops, made a few logical errors in my solution a few posts back.


    public static int substring(String str1,...
  2. Replies
    13
    Views
    5,140

    Re: First string is a substring of another

    you're missing a closing parenthesis :)


    str2.equals(str1.substring(i, str1.length()) + str1.substring(0, str2.length() - i)))
  3. Replies
    13
    Views
    5,140

    Re: First string is a substring of another

    public static int substring(String str1, String str2)
    {
    for (int i = 0; i+str2.length() < str1.length(); i++)
    {
    if (str2.equals(str1.substring(i,i+str2.length()))
    {...
  4. Replies
    13
    Views
    5,140

    Re: First string is a substring of another

    You're return statements are pre-mature. The program hasn't completely checked that the string is contained str2 is a substring of str1, but you're saying it is. Also, return is a Java keyword. You...
  5. Replies
    13
    Views
    5,140

    Re: First string is a substring of another

    Here's a simple algorithm to check if a substring is contained within another string:

    1. start from the beginning of the larger string
    2. If the remaining characters is greater than the length of...
Results 1 to 5 of 5