05.01_java Language Basics (Array overview and Definition Format description) (learn)
- A: Why do we have arrays (containers)
- To store multiple values of the same data type
- B: Array Concept
- An array is a collection of multiple elements that store the same data type. can also be seen as a container.
- Arrays can store either the base data type or the reference data type.
- C: Array definition Format data type [] Array name = new data type [length of array];
05.02_java Language Basics (initializing dynamic initialization of arrays) (mastering)
- A: What is the initialization of an array
- is to open up contiguous memory space for arrays and assign values to each array element
- B: How to initialize an array
- A: Dynamic initialization only specifies the length, the system gives the initialization value
- B: Static initialization gives the initialization value, the system determines the length of the
- C: Dynamic initialization format:
- data type [] Array name = new data type [array length];
- D: Case Demo
- Output array names and arrays elements
05.03_java Language Basics (memory allocations in Java and differences between stacks and heaps)
- A: Stack (Master)
- B: Heap (Master)
- Storing new arrays or objects
- C: Method Area
- Object-oriented section explanation
- D: Local Method area
- E: Register
05.04_java Language Basics (array of memory plots 11 arrays) (master)
05.05_java Language Basics (array of memory plots 22 arrays) (Learn)
05.06_java Language Basics (array of memory plots 33 references two arrays) (learn)
- A: Drawing Demo
- Three references, two array references to the same address
05.07_java Language Basics (initializing static initialization of arrays and memory graphs) (master)
- A: The Static initialization format:
- Format: data type [] Array name = new data type []{element 1, element 2,...};
- Simplified format:
- data type [] Array name = {element 1, element 2,...};
- B: Case Demo
- Explanation of the logarithm group
- Output array names and arrays elements
- C: Drawing Demo
05.08_java Language Basics (two common minor problems with array manipulation out of bounds and null pointers) (master)
- A: Case Demo
- A:arrayindexoutofboundsexception: Array index out-of-bounds exception
- Reason: You have accessed an index that does not exist.
- B:nullpointerexception: null pointer exception
- Cause: The array is no longer pointing to heap memory. You also use the array name to access the element.
- Int[] arr = {A-i};
- arr = null;
- System.out.println (Arr[0]);
05.09_java Language Basics (Array operation 1 times calendar) (master)
- A: Case Demo
- Array traversal: Is the output of each element in the array sequentially.
- Properties of the array: length of the arr.length array
- Maximum index of the array: arr.length-1;
- public static void print (int[] arr) {
- for (int i = 0;i < Arr.length; i++) {
- System.out.print (Arr[i] + "");
- }
- }
Copy Code
05.10_java Language Basics (Array operations 2 get the maximum) (master)
- a: Case demo
- array gets the maximum value ( Gets the maximum minimum value in the array)
- public static int Getmax (int[] arr) {
- int max = arr[0];
- for (int i = 1;i < arr.length; i++) { //from the second element of the array, start traversing the /li>
- if (Max < arr[i]) { &nb sp; //If Max records a value less than the element in the array
- max = arr[i]; &nb sp; //max record larger
- }
- }
-
- return max;
- }
copy code
05.11_java Language Foundation (operation of Array 3 inversion) (master)
- A: Case Demo
- array element inversion (that is, swapping elements)
- public static void Reversearray (int[] arr) {
- for (int i = 0;i < ARR.LENGTH/2; i++) {
- Arr[0] and arr[arr.length-1-0] Exchange
- ARR[1] and Arr[arr.length-1-1] Exchange
- ARR[2] and Arr[arr.lentth-1-2]
- //...
- int temp = Arr[i];
- Arr[i] = arr[arr.length-1-i];
- Arr[arr.length-1-i] = temp;
- }
- }
Copy Code
05.12_java Language Basics (Array operations 4 look-up Table method) (master)
- A: Case Demo
- Array Lookup Table method (according to the keyboard input index, find the corresponding week)
- public static char Getweek (int week) {
- Char[] arr = {', ' one ', ' two ', ' three ', ' four ', ' V ', ' VI ', ' Day '}; Define a weekly table
- return Arr[week]; Get the elements in a table by index
- }
Copy Code
05.13_java Language Basics (array of Operations 5 basic Find) (master)
- A: Case Demo
- Array element Lookup (finds the index of the first occurrence of the specified element in the array)
- public static int GetIndex (int[] arr,int value) {
- for (int i = 0;i < Arr.length; i++) {//array traversal
- if (arr[i] = = value) {//If the elements in the array match the elements found
- return i;
- }
- }
- return-1;
- }
Copy Code
05.14_java Language Basics (two-dimensional array overview and Format 1) (Learn)
- A: A Two-dimensional array overview
- B: two-dimensional array format 1
- int[][] arr = new int[3][2];
- C: Interpretation of the two-dimensional array format 1
- D: Precautions
- A: The following format can also represent a two-dimensional array
- 1: Data type array name [] = new data type [m][n];
- 2: Data type [] array name [] = new data type [m][n];
- B: Note the differences defined below
-
- int x;
- int y;
- int x, y;
- Int[] x;
- Int[] y[];
- Int[] x,y[]; X is a one-dimensional array, and Y is a two-dimensional array
Copy Code
- E: Case Demo
- Define two-dimensional arrays, output two-dimensional array names, one-dimensional array names, one element
05.15_java Language Basics (memory plots for two-dimensional array format 1) (Learn)
- A: Drawing Demo
- Drawing explains the problem of the above two-dimensional array name, one-dimensional array name, and the value of an element
05.16_java Language Basics (Explanation of two-dimensional array format 2 and its memory plots) (learn)
- A: Two-dimensional array format 2
- int[][] arr = new int[3][];
- B: Interpretation of the two-dimensional array format 2
- C: Case Demo
- Explain formats, output data, and draw memory graphs
05.17_java Language Basics (Explanation of two-dimensional array format 3 and its memory plots) (learn)
- A: Two-dimensional array format 3
- Int[][] arr = {{1,2,3},{4,5},{6,7,8,9}};
- B: Interpretation of the two-dimensional array format 3
- C: Case Demo
- Explain formats, output data, and draw memory graphs
05.18_java Language Basics (two-dimensional array Exercise 1-times Calendar) (master)
- A: Case Demo
- Requirements: two-dimensional array traversal
- The outer loop controls the length of the two-dimensional array, which is actually the number of one-dimensional arrays.
- The inner loop controls the length of a one-dimensional array.
- Int[][] arr = {{1,2,3},{4,5},{6,7,8,9}};
- for (int i = 0;i < Arr.length; i++) {//get to one-dimensional array in each two-dimensional array
- for (int j = 0;j < Arr[i].length; J + +) {//Gets the elements in each one-dimensional array
- System.out.print (Arr[i][j] + "");
- }
- System.out.println ();
- }
Copy Code
05.19_java Language Basics (two-dimensional array exercises 2 summation) (master)
- A: Case Demo
-
- Requirements: Sum of annual sales of company
- the data for a company by quarter and month are as follows: unit (million)
- first quarter: 22,66,44
- second quarter: 77,33,88
- third quarter: 25,45,65
- fourth quarter: 11,66,99
-
- int[][] arr = {{22,66,44},{77,33,88},{25,45,65},{11,66,99}};
-
- int sum = 0; &nb Sp //define variables to record the result of each addition
- for (int i = 0;i < arr.length; i+ +) { //get each one-dimensional array
- for (int j = 0;j < Arr[i].length; J + + ) { //Gets the elements in each one-dimensional array
- sum = sum + arr[i][j]; ; //cumulative
- }
- }
-
- System.out.println (sum);
Copy Code
05.20_java Language Basics (Study questions in Java and parametric transfer problems and illustrations) (master)
- A: Case Demo
-
- Read the program to write the results, and draw the memory diagram to explain
- public static void Main (string[] args) {
- int a = 10;
- int B = 20;
- System.out.println ("A:" +a+ ", B:" +b);
- Change (A, b);
- System.out.println ("A:" +a+ ", B:" +b);
- Int[] arr = {1,2,3,4,5};
- Change (arr);
- System.out.println (arr[1]);
- }
- public static void Change (int a,int b) {
- System.out.println ("A:" +a+ ", B:" +b);
- A = b;
- b = A + B;
- System.out.println ("A:" +a+ ", B:" +b);
- }
- public static void Change (int[] arr) {
- for (int x=0; x<arr.length; x + +) {
- if (arr[x]%2==0) {
- arr[x]*=2;
- }
- }
- }
Copy Code
"Moving Bricks" Android Primer (4)-Java Development Programming Basics-arrays