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

  • Home
  • SEARCH
  • 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 7694523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:20:23+00:00 2026-05-31T21:20:23+00:00

I have created this function to check abecedarian with while loop (A word is

  • 0

I have created this function to check abecedarian with while loop (A word is said to be “abecedarian” if the letters in the word appear in alphabetical order, such as “abdest”)-

public static boolean isAbecedarian(String s) {
                int index = 0;
                char c = 'a'; 
                while (index < s.length()) {
                        if (c > s.charAt(index)) {
                                return false;
                        }
                        c = s.charAt(index); 
                        index = index + 1;

                }
                return true;
        }

I want to change this function to a recursive function and I have written this function –

public static boolean isAbecedarianrec(String s){
                char first = s.charAt(0);
                char second = first ++;
                if (first<second){
                         return isAbecedarianrec(s);
                }

                return false;
}

recursive function is not working as it should and I am not getting the expected result. Please check and help me to pin point the issue with this function.

Note – As I mentioned this is not a homework question and it is part of my self Java learning.

  • 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-31T21:20:24+00:00Added an answer on May 31, 2026 at 9:20 pm

    Typically with recursion you need two things:

    1. A base case (e.g. empty string, zero, etc.)
    2. A way to check part of the more complex case, and then reduce it to a simpler recursive call.

    The empty string does form a good base case here – it’s trivially abecedarian. So the first part of your recursive method should be to check for the empty string and return true. This forms the base case that will be the termination of your recursive method in the “happy path” case.

    Otherwise, you know you have a non-empty string. The recursive decomposition can be achieved by checking its first character, then recursively calling with the rest of the string. However, in order to perform the check, you’ll need to remember what the previous character of the string was (just like c in the iterative method), so you’ll need an additional argument to the recursive call to act as a sort of variable.

    This is not uncommon with recursion – often the majority of the work is done in a “helper” method, and the public method just calls this with initial/dummy values.

    Putting these together then, a solution would look something like the following:

    // s must not be null
    public boolean isAbecedarianrec(String s) {
        return isAbecedarianRecImpl(s, (char)0);
    }
    
    private boolean isAbecedarianRecImpl(String s, char c) {
        if (s.isEmpty())
            return true;
        else {
            if (c > s.charAt(0))
                return false;
            else
                return isAbecedarianRecImpl(s.substring(1), s.charAt(0));
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a loop created with each, check this example: $('.foo').each(function(i){ //do stuff });
Inside a function I have created, I have this loop that checks if the
i have created a module with this among others this function in it: <?php
I have dialog created like this $('#add_error').click(function(e) { $('<div>') .load('/someaction/format/html/') .dialog({ title: 'Some title',
I have this problem whereby, i have created a user defined function within php.
I have this function: CREATE OR REPLACE FUNCTION CREATE_AIRSPACE_AVAILABILITY_RECORD (cur_user VARCHAR, start_time VARCHAR, start_date
Ok, I have one JavaScript that creates rows in a table like this: function
How would I create a nested list, I currently have this public function getNav($cat,$subcat){
I have this class that have a function to load other classes and create
I have created this code, and when I run it, don't get any errors

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.