Wrapper class for Java 13-6 char character

Source: Internet
Author: User
Tags wrapper

1. 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

Construction Method:
Character (char value)

1  Public classCharacterdemo {2  Public Static voidMain (string[] args) {3 //Creating Objects4 //Character ch = new Character ((char));5Character ch =NewCharacter (' a ');6SYSTEM.OUT.PRINTLN ("Ch:" +ch);7 }8}

2, character of several methods:
1. public static Boolean isuppercase (char ch): Determines whether the given character is uppercase characters
2. public static Boolean islowercase (char ch): Determines whether the given character is lowercase characters
3. public static Boolean isdigit (char ch): Determines whether a given character is a numeric character
4, public static char touppercase (char ch): Converts the given character to uppercase characters
5, public static char tolowercase (char ch): Converts the given character to lowercase characters

3. Count the number of uppercase characters, lowercase alphabetic characters, and numeric characters that appear in a string. (No other characters are considered)
Analysis:
A, keyboard input string
B, define 3 int variables: smallcount, Bigcount, Numbercount
C, convert the string to an array, and traverse the judgment
A, the characters are lowercase letters: smllcount++
b, the character is uppercase: bigcount++
C, the character is a number: numbercount++
D, Output results
E, written Method:
A, return type: void prints the result directly
B, parameter list: string str

1 ImportJava.util.Scanner;2  Public classCharacterTest1 {3 4  Public Static voidMain (string[] args) {5 //Create keyboard Entry6Scanner sc =NewScanner (system.in);7System.out.println ("Please enter string:");8String str =sc.nextline ();9 Ten //Calling Methods One choose (str); A } -  - //Defining Methods the  Public Static voidChoose (String str) { - //Define 3 variables - intSmallcount = 0; - intBigcount = 0; + intNumbercount = 0; - //Convert a string to an array + Char[] ch =Str.tochararray (); A //iterating and judging an array at  for(intx = 0; x < ch.length; X + +){ - //Public Static Boolean islowercase (char ch): Determines whether the given character is lowercase characters - if(Character.islowercase (ch[x])) { -Smallcount + +; - } - Else if(Character.isuppercase (ch[x])) { inBigcount + +; - } to Else if(Character.isdigit (ch[x])) { +Numbercount + +; - } the } *System.out.println ("The lowercase letters in a string have a total of" +smallcount+ "); $SYSTEM.OUT.PRINTLN ("Uppercase letters in a string have a total of" +bigcount+ ");Panax NotoginsengSystem.out.println ("The number in the string has a total of" +numbercount+ "); - } the  +}

Wrapper class for Java 13-6 char character

Related Article

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.