1: Two-dimensional array (understanding)
(1) The element is an array of one-dimensional arrays.
(2) Format:
- data type [] Array name = new data type [m][n];
- data type [] Array name = new data type [m][];
- data type [] Array name = new data type [][]{{...},{...},{...}};
- data type [] Array name = {{...},{...},{}};
(3) Case (Master):
- Traversal of two-dimensional arrays
- Summation of two-dimensional arrays
- Yang Hui Triangle
Yang Hui triangle:
Public classArray2demo { Public Static voidMain (string[] args) {Scanner sc=NewScanner (system.in); intn =Sc.nextint (); int[] arr =New int[N][n]; /** Idea: * A: The first and last columns of any row are 1; * B: Starting from the third row, each data is the previous column of its previous row and the Benlie of its previous row; * C: First define a two-dimensional array, the number of rows if n , the number of columns is also N; * D: Assigns a value of 1 to the first and last column of any row of this two-dimensional array; * E: Assigns a value to other elements according to the law, starting with the third row, each of which is the sum of the previous column of the previous row and the column of the previous row. * F: Traverse This two-dimensional array. */ for(inti=0;i<arr.length;i++) {arr[i][0] = 1; Arr[i][i]= 1; } for(inti=2;i<arr.length;i++){ for(intj=1;j<i;j++) {Arr[i][j]= Arr[i-1][j-1] + arr[i-1][j]; } } for(inti=0;i<arr.length;i++){ for(intj=0;j<=i;j++) {System.out.print (Arr[i][j]+ "\ T"); } System.out.println (); } }}
2: Two study questions (understanding)
(1) Problem of parameter Passing in Java
Only values are passed in Java.
Basic type: Changes in formal parameters do not affect actual parameters
Reference type: Changes in formal parameters directly affect actual parameters
(2) Data encryption issues
Synthesis of small cases.
/*A company uses a public telephone to transmit data information, the data is less than 8-bit integer, in order to ensure security, in the delivery process requires encryption, encryption rules are as follows: first, the data is reversed, then each digit is added 5, and divided by the remainder of 10 instead of the number, and finally the first and last digit exchange. Give an integer that is less than 8 bits, and then print the encrypted result in the console. Title: A: The data is less than 8 bits of an integer that defines an int type of data int number = 123456; B: Encryption rule A: First reverse the data result 654321 B: Then add each digit to 5, and then divide by the remainder of 10 instead of the number result 109876 C: the first and last Bit-digit exchange result 609871 C: Outputs the encrypted results in the console*/ Public classJmdemo { Public Static voidMain (string[] args) {Scanner sc=NewScanner (system.in); System.out.println ("Please enter a data:"); intNumber =Sc.nextint (); String result=JM (number); System.out.println ("After encryption:" +result); } Public StaticString JM (intNumber ) { int[] arr =New int[8]; intindex = 0; while(Number > 0) {Arr[index]= number%10; Index++; number/=10; } for(inti=0;i<index;i++) {Arr[i]= (arr[i]+5)%10; } inttemp; Temp= Arr[0]; arr[0] = arr[index-1]; Arr[index-1] =temp; String s= ""; for(inti=0;i<index;i++) {s+=Arr[i]; } returns; }}
3: Object-oriented (mastering)
(1) Object-oriented
Object-oriented is a process-oriented programming idea
(2) Object-oriented thought characteristics
- A: It's a thought that's more in line with our thinking habits.
- B: Simplifying Complex things
- C: Let's turn from the executor to the conductor
Example:
Buy a computer
Washing clothes
Cook
...
Everything is object.
(3) Load the elephant into the refrigerator (understanding)
- A: Process-oriented implementation
- B: Object-oriented implementation
Note: How do we make our operations more consistent with object-oriented thinking?
- A: What are the classes
- B: What are the members of each class
- C: Class-To-class relationships
(4) Classes and objects
A: Things in the real world
Basic description of a property thing
The function of a behavioral thing
The most basic unit in the B:java language is the class. So, we're going to use classes to show things.
C: Class
member variables Things properties
Member Methods thing behavior
D: Class: Is a set of related properties and behaviors. is an abstract concept.
Object: is the concrete existence of this kind of thing, is a concrete instance. Object
Example:
Student: Class
Monitor: Object
(5) Definition and use of class
A: Definition of class
The member variable definition format is the same as before, where the location is different, in the class, outside the method.
The member method definition format is the same as before, which is to remove the static.
B: Use the contents of the class
A: Create an object? Format
Class Name Object name = new class name ();
B: How do I use member variables and member methods?
Object name. Member Variable
The name of the object. Member method ()
(6) Case:
A: Definition and use of student class
B: Definition and use of mobile phone class
(7) Memory diagram
A: Memory diagram of an object
B: Memory diagram of two objects
C: Memory diagram of three objects
(8) Development, design, and characteristics of Java programs
- A: Development: Is the constant creation of objects, through the object call function
- B: Design: To manage and maintain relationships between objects
- C: Features
- Packaging
- Inherited
- Polymorphic
Two-dimensional arrays and object-oriented fundamentals