Java String class Exercises

Source: Internet
Author: User

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

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.