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 5929759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:28:01+00:00 2026-05-22T14:28:01+00:00

Describe the following two functions and whether they perform the same task – public

  • 0

Describe the following two functions and whether they perform the same task –

public int Jane1(String input, char aChar) {
    int count = 0;
    int index = input.indexOf(aChar);
    while (index >= 0) {
        count++;
        index = input.indexOf(aChar, index + 1);
    }
    return count;
}

public int Jane3(String input, char aChar) {
    int index = input.indexOf(aChar);
    if (index < 0) return 0;
    return Jane3(input.substring(index + 1), aChar) + 1;
}

I think they don’t perform the same task, however I’m not sure of the explanation. Jane3 function uses a recursive call to return the length of the String input, where as Jane1 returns the length of the String. Struggling to get my head around the difference between returning sub string (which I think is a String result), and index of?

  • 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-05-22T14:28:02+00:00Added an answer on May 22, 2026 at 2:28 pm

    They both perform the same task. Count how many times aChar appears at input. The first one uses an overloaded version of indexOf and a loop to achieve the result. The second version will split the input at the first occurrence of aChar and call itself recursively for the second halve. The result is an integer (0 if no occurrence happens, or 1 + the number of times the character was found in the second halve).

    PS: Why don’t you write a main class and run / debug both of those methods for different inputs? It is the best way to learn…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got the following two classes in C#: public class MyFirstClass : IMyFirstClass {
I have two tables in Hive, t1 and t2 >describe t1; >date_id string >describe
I've got the following deadlock graph that describes two sql statements that are deadlocking
Can anyone describe the following php function: function get_setting_value($settings_array, $setting_name, $default_value = ) {
I want to describe the following situation in an UML Classdiagram: A day, on
Describe the output of the following SQL query: select custId, name from customer where
I have the following RSpec example which is passing: describe UsersController do it should
I am using the following InnoDB tables in mysql to describe records that can
I am trying to comprehend Perl following the way describe in the book Minimal
I don't know the exact words to describe this behavior in the following pages:

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.