one-dimensional arraysdefinition: HasSame Data typeSet of data.Statement: int []a=new int[3];Explanation: The data type of the array is int, the array length is 3, there are 3 elementsYou can assign a value to an element in the following ways: a[0]=1;a[1]=2;a[2]=3;Summary: The length of the element is 3, but the subscript of the array starts from 0, but the maximum value can be seen as 2, that is, the length is longer than the subscript large 1,java, that is, a.length=3; there is also a common way to declare arrays: int []a={1,2,3}; Utility and equivalence above in order to verify the basic properties of the above array, write a simple test:
This test mainly verifies the way the array is declared and verifies the result of the array length value:to print an element in an arrayAs an array of examples, a[0]=1; 0 is the subscript for the array, and the subscript is an important identifier for accessing the element in the arrayfor (int i=0;i<a.length;i++){System.out.println (A[i]);}The code prints the elements in the array a[]A simple first look is a For loop statementloop condition combined with array subscript knowledge, int i=0; Since the array subscripts are all starting from 0, and i<a.length; is also mentioned above, the array subscript is 1 smaller than the length, so the statement will understandVerify the output:
Results:
Two-dimensional arrays:Learning to the array of this piece, I understand that my logical ability is a bit bad ... But you can exercise slowly. Suggestion: Be sure to knock more code, look for the Java case that topic do about the two-dimensional array, the teacher is not too much, not to do hard requirements, this article on the simple point of use more places
Declaration: int [][]a=new int[2][3], or int a[][]={{1,2,3},{2,3}}, master the following two-dimensional array element traversal, print out each element because it is a two-dimensional array with two for loops
The result is:
About sorting: Simple to mention a common use of more methods: bubble Sort method Body thought: 22 comparison
Results:
Finally say: This bubble sort, logic bad, can first back down, later use slowly understand. Do more questions, the array is finished, you can try to do the multiplication table and so on.
From for notes (Wiz)
"Java Development" array Basic Learning