Java chapter II variables, data types, and operator notes

Source: Internet
Author: User
Tags arithmetic operators

Java chapter II variables, data types, and operators

One , variable: a basic unit that stores data.

Second , the Declaration and assignment of variables:

1) Declare and assign values: Data type variable name = value ; Example:int price=1000;

2) Declaration, assignment is divided into two steps: Data type variable name ; Example: int price;

variable Name = value ; price=1000;

Three , the data type 2 kinds:

1) basic data type 8 kinds:

        Byte  length: - 128~127 ( -2 7 2 7 1 )

2 of the Short-2 , minus 1 in the four-time square .

The Int-2 of the two to 2 minus 1 .

The Long-2 of the Five-to -2 reduction of 1 99l

Float 99f

Doubles Double price=32.5;

Boolean True (true) False (false) bolean isbrand=true

Char one character , two byte range 0~65535 reference ASCII character encoding table Char sex=   ' Male '; char num=65; ( output A)

2) Reference data type:

String strings name=" Zhang San ";

Class

Interface

Four , the variable naming specification:

English words or pinyin

Initials : Starts with letters, underscores, and$ ;

When multiple words are composed of variable names: Named by the Camel, example:studentname

The name of the variable should be the result of knowing the meaning of the name

assignment operator:= assigns the right value to the left

Six , arithmetic operators:+-*/% ( remainder )

Seven ,num++;//num=num+1;num+=1;

Num--;//num=num-1;num-=1;

System.out.println (--num);// calculate and re-output first (++num same )

System.out.println (num--);// Output recalculation First (num++ same )

Eight ,double avg= (90+99)/3.0 Automatic type conversion occurs

the conditions for automatic type conversion ;

1) Type-compatible:(int and double are numeric )

2) The target type is greater than the source type

Ix. Coercion Type conversion: (data type) variable name (data type) value

Example:double num=5.5; int result= (int) num;

or int result= (int) 5.5;

Java chapter II variables, data types, and operator notes

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.