Java Api--character Class

Source: Internet
Author: User

1. Overview of the character class· The Character class wraps the value of a basic type char in an object · In addition, the class provides several methods to determine the categories of characters (lowercase letters, numbers, and so on) and to convert characters from uppercase to lowercase, and vice versa 2. Construction Method
 Public class CharacterDemo01 {    publicstaticvoid  main (string[] args) {           Create object        new Character (' a ');        System.out.println ("ch:" +ch);}    }
3.character class member method public static Boolean isuppercase (char ch): Determines whether the given character is uppercase characters        public static Boolean islowercase (char ch): Determines whether the given character is lowercase characters       public static Boolean isdigit (char ch): Determines whether a given character is a numeric character       public static char touppercase (char ch): Converts the given character to uppercase characters       public static char tolowercase (char ch): Converts the given character to lowercase characters
 Public classCharacterDemo02 { Public Static voidMain (string[] args) {//Public Static Boolean isuppercase (char ch): Determines whether the given character is uppercase charactersSystem.out.println ("isuppercase:" + character.isuppercase (' A '));//isuppercase:trueSystem.out.println ("isuppercase:" + character.isuppercase (' a '));//Isuppercase:falseSystem.out.println ("isuppercase:" + character.isuppercase (' 0 '));//Isuppercase:falseSystem.out.println ("-----------------------------------------"); //Public Static Boolean islowercase (char ch): Determines whether the given character is lowercase charactersSystem.out.println ("islowercase:" + character.islowercase (' A '));//Islowercase:falseSystem.out.println ("islowercase:" + character.islowercase (' a '));//islowercase:trueSystem.out.println ("islowercase:" + character.islowercase (' 0 '));//Islowercase:falseSystem.out.println ("-----------------------------------------"); //Public Static Boolean isdigit (char ch): Determines whether a given character is a numeric characterSystem.out.println ("isdigit:" + character.isdigit (' A '));//Isdigit:falseSystem.out.println ("isdigit:" + character.isdigit (' a '));//Isdigit:falseSystem.out.println ("isdigit:" + character.isdigit (' 0 '));//isdigit:trueSystem.out.println ("-----------------------------------------"); //Public Static char touppercase (char ch): Converts the given character to uppercase charactersSystem.out.println ("toUpperCase:" + character.touppercase (' A '));//touppercase:aSystem.out.println ("toUpperCase:" + character.touppercase (' a '));//touppercase:aSystem.out.println ("-----------------------------------------"); //Public Static char tolowercase (char ch): Converts the given character to lowercase charactersSystem.out.println ("toLowerCase:" + character.tolowercase (' A '));//tolowercase:aSystem.out.println ("toLowerCase:" + character.tolowercase (' a '));//tolowercase:a    }}

4. Exercises: count the number of uppercase characters, lowercase alphabetic characters, and numeric characters in a string. (No other characters are considered)

 Public classCharacterDemo03 { Public Static voidMain (string[] args) {//define three statistical variables.         intBigcount = 0; intSmallcount = 0; intNumbercount = 0; System.out.println ("Please enter a string:"); Scanner SC=NewScanner (system.in); String Line=Sc.nextline (); Char[] ch =Line.tochararray ();  for(inti = 0; i < ch.length; i++){            if(Character.isuppercase (Ch[i])) Bigcount++; Else if(Character.islowercase (Ch[i])) Smallcount++; Else if(Character.isdigit (Ch[i])) Numbercount++; }        //output results can beSYSTEM.OUT.PRINTLN ("Uppercase:" + Bigcount + "X")); System.out.println ("Lowercase letters:" + Smallcount + "X"); System.out.println ("Numeric characters:" + Numbercount + "X"); }}

Output Result:

Please enter a string: Hello 123 ABCAA Capital Letter: 3 Lowercase letters: 7 numeric characters: 3

Java Api--character Class

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.