Sixth day of Java learning

Source: Internet
Author: User

1: two-dimensional Array (understanding) (1) element is an array of one-dimensional arrays. (2) Format: A: Data type [] [] Array name=Newdata type [m][n]; A:intArr[][] =New int[4] [3]; B:int[] arr[] =New int[4] [3]; C:int[] arr =New int[4] [3]; Example:int[] x,y[];//defines an x one-dimensional array and a Y-two-dimensional array            int[] arr =New int[3] [2];//Dynamic InitializationSystem.out.println (arr);//Address ValueSystem.out.println (Arr[0]);//address of one-dimensional array arr[0]System.out.println (arr[1]);//address of one-dimensional array arr[1]System.out.println (arr[2]);//address of one-dimensional array arr[2]System.out.println (arr[1][1]);//the index number in the one-dimensional array arr[1] is 1 stored valueB: Data type [] array name=Newdata type [m][]; int[] arr =New int[3] [];//Number of columns not given, can be dynamically given, this time is a change of numberSystem.out.println (Arr[0]);//NULL because the number of elements of an array is not given, and space cannot be openedSystem.out.println (arr[1]);//NULLSystem.out.println (arr[2]);//NULLArr[0] =New int[2]; arr[1] =New int[3]; arr[2] =New int[1]; System.out.println (arr[0]);//one-dimensional array arr[0] address, given the number of elements, open up memory spaceSystem.out.println (arr[1]);//address of one-dimensional array arr[1]System.out.println (arr[2]);//address of one-dimensional array arr[2]C: Data type [] array name=NewData type [][]{{...},{...},{...}};//static initialization, which cannot exist concurrently with dynamic initializationD: Data type [] Array name = {{...},{...},{}};//Static Initialization        int[] arr = {{1,4,6},{3,8},{5}};//below the stack, open a two-dimensional array of arr space, and then heap, first open three array of one-dimensional space, each space value is NULL, each has an address, according to the static initialization of the value of the three one-dimensional array will quickly open up the corresponding elements of space, each one array has an address, Instead of the null address value of three single arrays, if you access the ARR array inside the stack, you need to access the corresponding space in the heap space through the address value. System.out.println (arr); System.out.println (arr[0]);//NULL because the number of elements of an array is not given, and space cannot be openedSystem.out.println (arr[1]);//NULLSystem.out.println (arr[2]);//NULL            (3) Case (Master): A: Traversal of two-dimensional arraysint[] arr = {{1,2,3},{4,5,6},{7,8,9}}; //Arr[0] = {n/a}; //Arr[1] = {4,5,6}; //Arr[2] = {7,8,9};System.out.print ("{");  for(inti=0;i<arr.length;i++) {System.out.print ("{");  for(intj=0;j<arr[i].length;j++){            if(j==arr[i].length-1){                if(i==arr.length-1) {System.out.print (Arr[i][j]+"}"); }Else{System.out.print (Arr[i][j]+"},"); }            }Else{System.out.print (Arr[i][j]+","); }}} System.out.print ("}"); B: Sum of two-dimensional arrays Public Static intYearsum (int[] x) {        intsum = 0;  for(inti=0;i<x.length;i++){             for(intj=0;j<x[i].length;j++) {sum+=X[i][j]; }            }        returnsum; } C: Yang Hui triangle Public Static voidYanghui (int[] x) {         for(inti=0;i<x.length;i++){             for(intj=0;j<=i;j++){                if((j==0) ) {X[i][j]= 1; System.out.print (X[i][j]+ "\ T"); }Else if((i==x[i].length-1) && (j==x[i].length-1) ) {X[i][j]= 1; System.out.print (X[i][j]+ "\ T"); }Else{X[i][j]= X[i-1][j-1]+x[i-1][j]; System.out.print (X[i][j]+ "\ T");        }} System.out.println (); }        }2: Two study Questions (understanding) (1) problem with parameter passing in JavaclassArgsdemo { Public Static voidMain (string[] args) {intA = 10; intb = 20; System.out.println ("A:" +a+ ", B:" +b);//a:10,b:20Change (A, b); System.out.println ("A:" +a+ ", B:" +b);//The operation from the method area in the stack is freed a:10,b:20        int[] arr = {1,2,3,4,5};        Change (arr); System.out.println (arr[1]);//The data in the address point to the heap has changed 4    }     Public Static voidChangeintAintb) {//a=10,b=20System.out.println ("A:" +a+ ", B:" +b);//a:10,b:20A = b;//a=20b = A + B;//b=40System.out.println ("A:" +a+ ", B:" +b);//a:20,b:40    }     Public Static voidChangeint[] arr) {//arr={1,2,3,4,5};         for(intx=0; x<arr.length; X + +) {            if(arr[x]%2==0) {Arr[x]*=2; }        }        //arr={1,4,3,8,5};}} Only values are passed in Java. Basic type: The change of formal parameter does not affect the actual parameter reference type: The change of formal parameter directly affects the actual parameters (2) Data encryption problems in a small case of synthesis. //convert to reverse array         Public Static voidArrayintx) {        int[] arr =New int[8]; intindex = 0;  while(x>0) {Arr[index]= x%10; Index++; X/= 10; }         for(inti=0;x<index;x++) {System.out.print (arr[x]);            } System.out.println (); }    3: Object-oriented (master) (1Object-oriented object-oriented is a process-oriented programming idea (2object-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 and cooking ... Everything is Object (3put the elephant in the refrigerator (understanding) A: process-oriented implementation B: Object-oriented Implementation note: How to make our operations more consistent with object-oriented thinking?A: What are the classes B: What are the members of each class C: The Class-To-class relationship (4class and Object A: The basic description of things in the real world the function of things B:java the basic unit of the language is the class. So, we're going to use classes to represent things. C: class member variables things attribute 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. Example: Student: Class Leader: Object (5the definition and use of a: class defines a member variable in the same format as before, that is, 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=Newclass name (); B: How do you use member variables and member methods? The object name. Member variable object name. Member Method () (6) Case: A: Definition and use of student class B: definition and use of mobile phone class (7Memory Graph A: Memory of an object figure B: Memory figure of two objects C: Memory diagram of three objects (8Java program development, design and feature A: development: Is to constantly create objects, through the object invocation function B: Design: is to manage and maintain the relationship between Objects C: Feature A: Package B: Inheritance C: polymorphic

Sixth day of Java learning

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.