“This is the 14th day of my participation in the Gwen Challenge in November. Check out the details: The Last Gwen Challenge in 2021.”


Related articles

Java with Notes: Java with Notes


  • Just got home from work… Can do nothing… Water, hard water ~
   1, functions,1Function definition: is defined in a class has a specific function of a small independent program. Functions are also called methods. Format: modifier return value type function name (parameter type form parameter1Parameter Type Type parameter2,...). {execute statement;returnThe return value. } Return value type: the data type of the result of the function after it is run. Parameter type: Is the data type of the formal parameter. Formal argument: is a variable that stores the actual arguments passed to the function when it is called. Actual parameter: The specific value passed to the formal parameter.return: Terminates a function. Return value: The result of the operation, which is returned to the caller. Note: The return value isvoidWhen,returnYou can omit it. Example:// Add two values and return the sum
        public static int plus(int a , int b){
            return a+b;
        }


        2Function features: Defining functions encapsulates functional code. Easy to reuse this function. Functions are executed only when they are called. The advent of functions improves code reuse. Note: only functions can be called from a function, not defined from within a function. When a function is defined, the result of the function should be returned to the caller for processing.3) function application: stack: advanced after out4The overload concept: more than one function with the same name is allowed in the same class, as long as they have different arguments or parameter types. Features: Looks at the argument list regardless of the return value type. Benefits: Easy to read, optimized program design. Example:// Return the sum of two integers
                public static int add(int x,int y){returnx+y; }// Returns the sum of three integers with different numbers of arguments
                public static int add(int x,int y,int z){returnx+y+z; }// Return the sum of two decimals -- different argument types
                public static double add(double x,double y){returnx+y; } Example: Print custom multiplication tablespublic static void printCFB(int num){
                    for(int x = 1; x <= num; x++){
                        for(int y = 1; y <= x; y++){
                            System.out.print(y+"*"+x+"="+y*x+"\t"); } System.out.println(); }}public static void printCFB(a){
                    for(int x = 1; x <= 9; x++){
                        for(int y = 1; y <= x; y++){
                            System.out.print(y+"*"+x+"="+y*x+"\t"); } System.out.println(); }} If you pass a few, print them to the multiplication table9*9Multiplication table2, arrays,1Definition: Concept: a collection of data of the same data type. An array is just a container. Benefits: The elements in an array can be automatically converted from0Start numbering to make it easier to manipulate the elements. format1: Element type [] Array name =newElement type [number of elements or array length]; Example:int[] arr = new int[5]; format2: Element type [] Array name =newElement type []{element, element, element,....... }; Example:int[] arr = new int[] {1.2.3.4};
                    int[] arr = {1.2.3.4};
            

        2Memory allocation and features: Memory partition: register local method area method area stack memory: features fast processing speed storage are local variables (variables within a method, only useful in the current method, such as: formal parameters, variables within a method,forParameters within the loop). Once a variable leaves its scope, its memory is automatically freed. All the variables are in the stack. Except for static variables. Local code block: {int a = 3;// Define the life cycle of a local variable} heap memory: Objects are stored. Anyone whonewWhatever is created is stored in the heap. Each entity has a header address value. Each variable in heap memory has a default initialization value, which varies by type. The integer is0, decimal0.0or0.0 fOolean,false,char '\u0000'. Garbage collection mechanism: reference data types (equivalent to Pointers in c++) are stored here. When arr =null; The reference disappears. Objects in the heap become garbage, and the garbage collection mechanism collects them. C++ is manual cleanup, using destructors for collection.3) operation common problem: an array: ArrayIndexOutOfBoundsException when access to the array does not exist when the Angle of the standard, the exception occurs. NullPointerException This exception occurs when a reference variable is being used to manipulate an entity without any reference to it.4) Common operation: core idea: is diagonal mark operation traversal: cycle traversal length: arr. Length storage: arr[0] = 1; Take: arr [I]; Maximum value operation: maximum or minimum valueint[] arr = {1.2.3.6.5.4};
                int max = 0;// Store the maximum value
                for(int i = 0; i <= arr.length-1; i++){
                    if(arr[i]>max){
                    max = arr[i]; 
                    }
                }
                System.out.println("The maximum value of this array is:"+max); Sort and find: write a separate detailed analysis! Selection sort: bubble sort:5) Array applications: If there is a correspondence between the data, and one of the correspondence is an ordered number, and used as a corner, this time to use arrays.6) Array of arrays: two-dimensional array: format1:int[][] arr = new int[3] [2]; Defines a two-dimensional array named ARR. In a two-dimensional array3One dimensional array. In each of these one-dimensional arrays2An element. Angle the elements of the first one-dimensional array as arr[0] [1] = 78; format2:int[][] arr = new int[3] []; Three one-dimensional arrays in a two-dimensional array. The initialization value of each one-dimensional array isnull. These three one-dimensional arrays can be initialized separately. arr[0] = new int[3];
                        arr[1] = new int[1];
                        arr[2] = new int[2]; format3:int[][] arr = {{1.2}, {2.3.7}, {6.7}}; Through:for(int i = 0; i < arr.length; i++){
                    for(int j = 0; j < arr[i].length; j++){
                        System.out.print("arr"+ arr[i][]j); }}Copy the code

The road ahead is long, I see no end, I will search high and low

If you think I bloggers write well! Writing is not easy, please like, follow, comment and give encouragement to the blogger ~ Hahah