"Java" java_08 character and Boolean values

Source: Internet
Author: User

1. Character type (2 bytes)

single quotation marks are used to denote character constants. For example ' A ' is a character, it is differentfrom ' A ', and' a ' represents a string containing a single character

Char types are used to represent characters in a Unicode encoded table

Unicode encoding is designed to handle all text in a variety of languages, it accounts for 2 bytes and can have 65536 characters;ASCII The code occupies 1 bytes and is allowed to have a number of characters, which is the Unicode encoding table of characters

Char Echar = ' a ';

Char CChar = ' medium ';

Unicode has encodings from 0 to 65535 , and they are usually used from ' \u0000 ' to ' \ The hexadecimal value between UFFFF ' is represented (the prefix is u for Unicode)

char c = ' \u0061;

The Java language also allows the use of the escape character ' \ ' to convert subsequent characters to other meanings,

char c2 = ' \ n '; represents a newline character.

Escape character

Meaning

Unicode Value

\b

BACKSPACE (backspace)

\u0008

\ n

Line break

\u000a

\ r

Enter

\u000d

\ t

tab (tab)

\u0009

\“

Double quotes

\u0022

\‘

Single quotation marks

\u0027

\\

Back slash

\u005c

2.boolean type (one bit, not one byte)

The Boolean type has two values,true and false, and cannot be 0 or not 0 Integer instead of true and false , which differs from the C language.

Boolean types are used to determine logical conditions and are generally used for program flow control .

Boolean flag;

Flag = ....;

if (flag) {

True Branch

} else {

False Branch

}

3. Code to indicate :

 Public classtestchartype{ Public Static voidMain (string[] agrs) {CharC1 = ' A '; CharC2 = ' Medium '; CharC3 = ' \ n ';        SYSTEM.OUT.PRINTLN (C1);        System.out.println (C2);                System.out.println (C3); //character A is forced to convert to an ASCII value        inti = c1 + 1;                System.out.println (i); CharC4 = (Char) I;                System.out.println (C4); //Cycle Print A-Z         for(intj=0;j<26;j++){            Chartemp = (Char) (c1+j);        System.out.print (temp); } System.out.print ("\ n");//line Break//Boolean type        Booleanb =true ; if(b) {System.out.println ("Boolean type"); }    }}

"Java" java_08 character and Boolean values

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.