Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8060321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:56:53+00:00 2026-06-05T09:56:53+00:00

I need to write a method which takes in 2 arrays as parameters and

  • 0

I need to write a method which takes in 2 arrays as parameters and returns true if the second array is a sub array of the first and false otherwise. I need to use only recursion without loops but I can use private methods.

So far this is what is have:

public static bool findSequence(char[] findIn, char[] toFind)
{
    return compare(findIn, toFind, num);
}

private static int num = 0;

private static bool compare(char[] findIn, char[] toFind, int num)
{
    for (int i = 0; i < findIn.Length; i++)
    {
        if (toFind[i] != findIn[num])
        {
            num++;
            return false;
        }
    }

    num++;
    return true;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T09:56:55+00:00Added an answer on June 5, 2026 at 9:56 am

    You are on the wrong way, since you have to use recursion and to avoid loops, and your code has loops and no recursion. I think that you should try a little bit harder, since this is very useful brain fitness. Anyway, this should work (and even understanding this could be a good exercise 🙂 ):

        public static bool FindSequence(char[] findIn, char[] toFind)
        {
            return FindSequence(findIn, toFind, 0, 0);
        }
    
        private static bool FindSequence(char[] findIn, char[] toFind, int posInFindIn, int posInToFind)
        {
            if (findIn.Length - posInFindIn < toFind.Length - posInToFind)
                return false;
            if (findIn[posInFindIn] == toFind[posInToFind])
            {
                if (posInToFind == toFind.Length - 1)
                    return true;
                else
                    if (FindSequence(findIn, toFind, posInFindIn + 1, posInToFind + 1))
                        return true;
            }
            return FindSequence(findIn, toFind, posInFindIn + 1, 0);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to write a method which takes any object and returns an equivalent
I need to write a tree search method which takes a type parameter T
I need to write effective and quick method to search byte array for given
I'm trying to write a method which takes a Map[K, Collection[V]] and converts it
I need to write a unit test for a method that takes a stream
I need to write a program, which will take an array of block pieces
I have a method which returns a array of ByteArray: public byte[][] Draw(ImageFormat imageFormat,
i need to write a method that takes in a string as a parameter
I'm writing a 'Sudoku' program, and I need to write a method to check
I need to write a program in Java which will read a relatively large

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.