Find a String length Using Recursion in Java

Problem:

Write a method that finds the string length Using Recursion in Java

Output:

Not applicable.

Solution:

public class string_length_recursion
{
  public static int length (String str)
  {
    if (str == null || str.equals(""))
    {
      return 0;
    }
    
    else
      return 1 + length(str.substring(1));
  }
  
  public static void main(String[] args)
  {
    System.out.println(length("Few"));
  }
}


1 comment :

  1. laser liposuction Korea's #1 Liposculpture Clinic. Lydian plastic surgery is the home of VIP patients. Celebrities, Influencers and Diplomats all know and trust Doctor An and Lydian plastic surgery clinic to provide detailed results.

    ReplyDelete

Follow Me

If you like our content, feel free to follow me to stay updated.

Subscribe

Enter your email address:

We hate spam as much as you do.

Upload Material

Got an exam, project, tutorial video, exercise, solutions, unsolved problem, question, solution manual? We are open to any coding material. Why not upload?

Upload

Copyright © 2012 - 2014 Java Problems  --  About  --  Attribution  --  Privacy Policy  --  Terms of Use  --  Contact