Build a comparison of recursive ideologically _ strings

Source: Internet
Author: User

String comparison

The rule for comparing the content of two strings is:

Compare each letter at the corresponding position. If one character is different, it is different. When one string is null and the other is not empty, it is different.

Use recursive methods to reproduce and compare whether the content of the two strings is the same.

Public class MyA {static boolean compare (String a, String B) {if (a. length ()! = B. length () return false; if (a. length () = 0) return true; if (a. charAt (0 )! = B. charAt (0) return false; return compare (. substring (1), B. substring (1);} public static void main (String [] args) {String s1 = "abcde"; String s2 = "abcded"; System. out. println (compare (s1, s2 ));}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.