Two-dimensional arrays
Define a two-dimensional array
int[][] arr;声明了一个二维数组 arr = new int[5][6];引用arr直接初始化 arr=new int[10][10]; 创建了一个更大的空间,以前 小的空间被回收,至于数据,你要的话就自己备份,不要就算了 arr=new int[100][1000]; 外面大括号所有。内部的带括号,行 int[][] number = {{1,2,3},{5,6},{0,8,9},{0,8,9}}; grade[1][1] = 80; grade[0][0] = 90;二位数组的空间:行*列 number.length求二维数组的length,求到了行的数量
For Each loop
int[] m = {1,2,3,4,5}; for(int element:m){ //element是每次循环得 到的数据,数据来自于m数组 System.out.print(element); }
The For Each loop is the introduction of a loop after JDK 1.5, which is called the For each and can also be referred to as a reinforced loop. Features access to elements without using subscripts. The downside is also the inability to use subscripts.
Method
Methods are statements that combine to perform a function together. Features:-method is a collection of steps to solve a problem-methods are contained in a class or object-created in a program, referenced elsewhere
Structure of the method
- Modifier: public (common) static (statically defines the access type of the method, tells the compiler how to call the method
- Return value type: The method may have a return value. Divided into have return and no return
- Name of the method: custom take Name
- The type of the parameter: The parameter is like a placeholder, and when the method is called, the value is passed to the parameter. Parameter tangible and actual arguments
- Method Body: Contains the specific statement, realizes the concrete function
Parameters
- parameter of formal parameter, receive the actual parameter. The actual arguments of the argument.
- The active invocation belongs to the argument and is called the formal parameter. The number of arguments must be the same as the number of parameters, the same type, the order
- A parameter can be a variable only, and an argument may be a variable or a constant.
-
parameter does not begin allocating memory when calling a function
public static int add(int num,String s){}public static void cheng(){}public static void main(String[] args) {// TODO Auto-generated method stubint sum = add(500,"华丽花哨"); cheng();add(); //调用方法cheng(); //调用累乘方法}
Where there is a return value to be based on the type defined, such as int. Void is no return value
Java Learning (v)