Title: string Delete digit uppercase to lowercase

Source: Internet
Author: User
Tags uppercase letter stringbuffer
Huawei Machine Test-string Delete digit uppercase to lowercase

Enter a string, delete the number that appears in the string, and then convert the uppercase letter to the lowercase letter output.

Package com.soft.wk;
Import Java.io.BufferedReader;
Import java.io.IOException;
Import Java.io.InputStreamReader;
Import Java.util.regex.Matcher;

Import Java.util.regex.Pattern;  /** * String deletion number uppercase to lowercase * @author wk * 2015-04-10 9:30 * * public class Deletenumberupercasetolowercase {public static  void Main (string[] args) {/** * loops the string, takes out each character, matches the regular, deletes it if it is a number, does not add it back to the stringbuffer * * BufferedReader in = new
		BufferedReader (New InputStreamReader (system.in));
		System.out.println ("Please enter a string of characters:");
		String str;
			try {str = in.readline ();
			String trim = Str.trim ();
			StringBuffer sb = new StringBuffer (); if (Trim!= null &&! "".
					Equals (Trim)) {for (int i = 0; I<trim.length (); i++) {Char ch = trim.charat (i);
					String character = Isnumber (ch+ "");
					if (character!= null) {sb.append (CH);
				} System.out.println ("The string after the number is deleted:" + sb.tostring ());
				String lowercase = sb.tostring (). toLowerCase (); System.out.println ("After the number is removed, the uppercase letters in the string are converted to smallWrite: "+ lowercase);
		} catch (IOException e) {e.printstacktrace (); }/** * matches number * @param numbers * @return/public static string Isnumber (string number) {String regex =
		"[0-9]+";
		Pattern p = pattern.compile (regex);
		Matcher m = p.matcher (number);
		if (!m.matches ()) {return number;
	return null;

 }
}

The program does not pass a lot of data test, just simple test.

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.