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.