Grammar basis of zero-based Java

A, Java identifier

What is the identifier?

Identifier is used to identify the class name, object name, variable name, a method name, the name of the array, a custom data type sequence of valid characters.

Valid identifier

①: letters, numbers, underscore "_" dollar sign "$" component, the numbers can not be used as the beginning.

②: Java can not put keywords and reserved words as identifiers.

③: identifier sensitive.

What are keywords and reserved words?

Second, what are the variables? Use variables?

What is a variable?

Amount during program operation can be changed, the variables used in the program, you must first create it and a name for it, and indicates the type of information it can store, which is called "variable declaration", also known as the container is created.

Use variables?

Declare variables: data type variable name int age;

Use variables: variable name = data age = 18;

Operating variables: output or print statements into calculates: system. out.print { "Age =" + age};

Third, the data type

 Operators: arithmetic, assignment, conditional logic, the relationship between the bit operators.

Ternary operator is the conditional operator: Syntax: relational expression? Expression 1: Expression 2 is used to represent logical judgment. Solving relational expression, according to the Boolean expression of the relationship between the value of the expression to determine the execution

Java flow control statements

Loop structure

Flow control statements: break and continue

break statement: Switch: End Analyzing case conditions; loop: loop end

continue statement: only role in the body of the loop: the end of this cycle of the loop body, and into the next cycle;

  In the for loop, continue statement causes the program to jump immediately to update statements.

  In while or do ... while loop, the program immediately jumps to the Boolean expression of the judge sentences

Fourth, the array

An array of concepts:

An array is a collection of the same type of data, in fact, an array is a container

Features: one kind of reference data types; arrays can store any type of data, including original data type and reference data types, but once the type of the array is specified, the specified type is used only for storing data.

One-dimensional array:

Array variable declarations:

Syntax: Data Type [] array name; described int [] num; float [] f; string [] str;

Caprice array creation and assignment to variables:

语法:数组名=new 数据类型[长度]; 如num= new int[4] 注:数组一旦声明其长度不可改变

数组声明的三种方式:

1:数据类型[]数组名=new 数据类型[长度];

2:数据类型[]数组名= {数据,数据,...,数据};

3:数据类型[]数组名= new 数据类型长度[]{数据,数据,...,数据}

数组元素的遍历:

数组的长度:数组名.length  如:for(int i=0;i<数组名.length;i++){system.out.print(数组名[i]);.}

数组的排序操作:冒泡排序和选择排序

二维数组:

二维数组变量的声明:

语法:数据类型[] [] 数组名; 如int [] [] num;

二维数组对象的创建,并赋值给变量

语法:数组名= new 数据类型[外长度] [内长度];如:num =new int[4] [3];

Guess you like

Origin www.cnblogs.com/scar1et/p/10946049.html