Java Interview Topics---even string __java

Source: Internet
Author: User
topic:
If a string is connected by two identical strings, the string is called a couple strings. For example, "xyzxyz" and "aaaaaa" are even strings, but "Ababab" and "Xyzxy" are not.
cows now give you a string s that contains only lowercase letters, you can delete 1 and or more characters from the end of the string s to ensure that after the deletion of the string or a couple of strings, Niu Niu want to know how long after the deletion of the length of the string.
Enter a description:
The input includes a string s, length of string (2≤length≤200), which guarantees that s is a string and is composed of lowercase letters.

Output Description:
Outputs an integer that indicates how long the longest string of strings can be obtained after the deletion. Ensure that the test data has a non 0 solution
Enter Example 1:
Abaababaab
Output Example 1:6
Import Java.util.Scanner;

public class Oustring {public

	static void Main (string[] args) {
		
		Scanner sc = new Scanner (system.in);
		String Str=sc.next ();
		SYSTEM.OUT.PRINTLN (Getlenth (str));

	private static int getlenth (String str) {

		int len=str.length ();
		int i=1;
		int end=len-1;//string Deletes the last one first;
	
		if (len<2 | | | len>200) return
			0;
		
		while (end>1) {
			String sub=str.substring (0, end);
			String str1=str.substring (0,END/2);
			String str2=str.substring (END/2, end);
			
			if (Str1.equals (str2)) {return end
				;
			} else{
				end=len-i;
				i++
			}
		}
		return 0;
	}
}

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.