Variables, data types and operators for beginners in java

 

variable

During the running of the program, the value in the space where the variable is stored changes, and this memory space is called a variable.

For ease of operation, give this space a name, called a variable name.

Syntax for variable names:

               Data type variable name; for example: char sex; //declare character variable sex to store gender

               variable name = value; eg: sex = 'male'; // store 'male'

               data type variable name=value; for example: char sex='male';

Variable naming rules:

 Common mistakes in variable names:

            1. The variable is used first without assignment

            2. Using an illegal variable name

            3. The variable name has the same name (the variable name cannot be the same name)

operator

Operators are divided into:

          1. Assignment operator In java, "=" is called assignment and "==" is a numerical comparison

          2. Arithmetic operators Arithmetic operators are the arithmetic we learned before   + addition   -   subtraction  * multiplication    /   division, the difference is that %  is the remainder

          3. Relational operators    

          

 

type of data

Commonly used data types in java are: int integer; double double-precision floating-point type; char character type; String string type

Conversion of data types:

        There are automatic conversions and forced conversions

         1. Automatic conversion is the conversion from low precision to high precision

           byte<short<int<long<float<double

         2. Forced conversion

            int   a=(int)1.2;

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326863061&siteId=291194637