Role:
1, can understand the program's three kinds of structure
2, can understand one-dimensional arrays, two-dimensional arrays, multidimensional arrays, irregular arrays
3, you can understand the shift operator and the random number class, console input
1 Three types of program structure
Sequential structure top-down progressive code execution
Select statements to determine the order of execution of code according to logic
A loop statement executes a block of code repeatedly based on logic
2 SELECT statement
1) If statement
1/Direct output
2/if...else
3/if...else If ... else if ...
4/if's three mesh operation such as (A>B)? a/b:a*b
2) switch statement
Switch statement: Can only be a Byte,int,char,short enumeration type
Statement format: switch (variable)
{
Case Variable 1: statement block 1; Break
Case Variable 2: statement block 2; Break
Default: statement;
}
3 Loop statements
1) While statement
Statement features: First judgment, after the execution of the loop
2) do ... while statement
Statement characteristics: At least one cycle, after the judgment
3) for Loop
4 Key Words
Break: Jump out of the loop body, direct cutoff loop.
Continue: Abort this cycle, direct the next cycle.
5 arrays
1) Array Declaration and initialization
A dynamic expression int[] Array name = number of new int[arrays]
b static initialization int[] Array name = new int[]{array value 1, array value 1 ...}
int[] Array name = {Array value 1, array value 1 ...}
2) array subscript (also known as array index)
The a array subscript is starting from 0
b Do not access array elements that do not exist, squeezing over the orientation of the array elements
3) The length of the array
A use the array name. length to get the array length
b Code, length traversal
4) Default and initialization of arrays
A defines an array, but does not assign a value to an array, in which case, the system defaults to arrays initialized
B Note: The default value for byte short int float dobuble is 0, and the Boolean default value is Flase
5) Conversion
A converts a string to a character
String str = "strvalue";
Char charval = str.charat (0);
b Converting a string to a character array
String str = "strvalue";
char[] Chararray = Str.tochararray ();
6) Two-dimensional array
A display initialization
1/int[][] results = {{1,2,3},{1,2,3}}; {{First row initial value},{second row initial value},{third row initial value} ...}
2/int[][] results = new int[][]{{1,2,3},{1,2,3}};
b Application
1/matrix Mutual Transfer the elements of a two-dimensional array are transferred to each other and stored in another two-dimensional array.
2/yang Hui triangle = Its hypotenuse is made up of the number 1, while the remaining number is the sum of two numbers on his shoulders.
C Understanding
1/an array: As a linear graph in geometry.
2/two-dimensional array: equivalent to a table
7) Multidimensional arrays
The dimensions of an array are the pairs of brackets that follow the type.
Number of multidimensional array elements = product of size on each of two dimensions
8) irregular arrays and regular arrays
Rule array: Linear distribution with the same number of elements per line
Irregular arrays: Different number of elements per line
A irregular array definition: Because multidimensional arrays are not linearly allocated in memory, multidimensional arrays can exist in an irregular form.
B as 1/int[][] results = {{1,2,3},{5,7},{0}}
2/int[][] x = new int[5][]
0 lines have 4 elements = x[0] = new Int[4] 1 lines have 3 elements = x[1] = new Int[3] ...
6 shift Operators
>> move right one time, equivalent to dividing by 2 (two bits to the right and 1 to the right)
<< move left one time, equal to 2 (move left two bits, left 0)
>>> two bits to the right, 0 on the left (no <<< operator)
7 Small applications
A generates a random number
int num = new Java.util.Random (). Nextint (10); Randomly generates 1-10 random numbers.
b input from keyboard, an input box appears
String obj_str = javax.swing.JOptionPane.showInputDialog ("Input number:");
int num_int = Integer.parseint (OBJ_STR);
Double Num_dou = double.parsedouble (OBJ_STR);
Javase Course Chapter I third lecture program control and arrays