| Data type |
Description |
Example |
| Int |
Integral type |
Used to store integers. For example. Number of trainees. Employee number of a company. The number of days in a year. Number of hours in a day |
| Double |
Double-precision floating-point type |
Used to store numbers with decimals. For example, the price of a commodity. The price of the world. The amount of loans the World Bank gives to other countries (regions). Employee wages |
| Char |
Character type |
Used to store a single character. e.g. male, female, score: gifted or poor |
| String |
String type |
Used to store a string of characters, such as employee name, product model, product introduction information |
I. Data type
1. Data type variable name: (Syntax below)
Double score;//declare dual-precision floating-point variable score storage score
String name; Declare string variable name store student name
char sex; Declaring a character type variable sex storage gender
2. Variable assignment: (Syntax below)
Variable name = value;
score=98.5;//Storage 98.5
Name= "Zhang San";//Storage "Zhang San"
sex= ' Male '//store ' male '
3. Merge the (1). (2) steps
Data type variable name = value; (Syntax below)
Double score = 98.5;
String name = "Zhang San";
char sex = ' male '
4. Call the variable. That is, using stored variables is called calling variables.
SYSTEM.OU.PRINTLN (variable name);
Two. Variable naming rules
1. The variable must begin with a letter. Underscore "-" or "$";
2. Variables can include numbers. But cannot begin with a number;
3. In addition to the underscore "-". $ "Variable name cannot contain any special characters;
4. You cannot use keywords in java. such as Int,public,class.
Three. Java provides a variety of operators, as described below.
1. Assignment operator (=);
2. Arithmetic operator (+,-,*,/,%);
3. Relational operators (>.>=.<.<=.==.! =
Four. Data type conversions are designed to facilitate operations between different types of data.
Five. Data type conversions include automatic type conversions and forced type conversions, which must meet certain conditions when automatic type conversions occur.
Six. Boolean types are used in Java to represent true and false. It has a value of two (true) (false).
Seven. The use of relational operators in Java can compare size, height, and so on, the result of comparison is a Boolean type.
Eight. Java provides the scanner class to obtain the information entered on the keyboard from the console.
Using Java to understand program logic, variables