Package Javafirst;public class StringTest02 {public static void main (string[] args) {//Exercise one uses case conversion String stra = "AbcD"; System.out.println ("Convert to lowercase:" + stra.tolowercase ()); System.out.println ("Convert to lowercase:" + stra.touppercase ());//Exercise two truncate a string to determine whether the content is the same (ignoring case) string StrB = "CADBCDE"; if ( Stra.substring (1). Equalsignorecase (Strb.substring (3,6)))//Two parameter start and end System.out.println ("two substrings Same"); ElseSystem.out.println ("Two substrings are not the same");//exercise three use regular expressions to determine whether text is a legitimate phone number string text = "13467890765"; String regex = "1\\d{10}";//1 and then follow the 10 0~9 of any number if (Text.matches (regex)) System.out.println ("This is a legitimate mobile number"); ElseSystem.out.println ("This is an illegal mobile phone number");//exercise four use the string generator, append the number StringBuilder Strbuilder = new StringBuilder ("floor"); for (int i = 1; I <= 10; i++) {strbuilder.append (i);} System.out.println (Strbuilder);//exercise five outputs a multiplication table for (int i = 1; i <, i++) {for (int k = 1; k < i + 1; k++) {int result = I * k; System.out.print (k + "X" + i + "=" + result + " ");} System.out.println ();}}}
Output results
Java String class Exercises