Parameter passing exercises

mxdx Package; 

public class the Mytest {
// Write the results to see the program

public static void main (String [] args) {
// A, B for the two local variables on the main method, two local variables defined

int A = 10;
int = 20 is B;
System.out.println ( "A:" + + A ", B:" B +); // 1. . direct printing, A = 10, B = 20 is
Change (A, B); // call change process ( note that two of the same name matches the following types of suitable methods that )

// local variable belongs to process the method call is completed or popped, popped method with local variables disappear
System.out.println ( "a:" + + a ", B:" B +); // 4. At this time, the value of the initial value of the print ab = 10 a, B = 20 is.

// define a one-dimensional array
int [] arr = {1,2,3 4, 5};
// change the method call
change (ARR);
System.out.println (ARR [. 1]); //5. Only 2 and 4, the new array of loop condition is {1,4,3,8,5}, and the printed value 4.
}

public static void Change (A int, int B) {

the System.out .println ( "A:" + + A ", B:" B +); // 2. . direct printing, 20 is A = 10.B =
A = B;
B = A + B;
System.out.println ( "A:" + + A ", B:" B +); // . 3 .. by simple calculation, 20 is A =, B = 40
}

public static void Change (int [] ARR) {
for (int X = 0 ; x <arr.length; x ++)loop
if (arr [x]% 2represents a one-dimensional array of elements is divided by 2 is 0 (i.e. an even number) is met cycling conditions
arr [x] * = 2;cycle to satisfy the conditions of the elements multiplied by 2, i.e., to form a new one-dimensional array
}
}
}



}
         
Summary
:

reference type passed as an argument passed is the address value of the parameter changes affect the argument.
The basic type as an argument (value transfer), change the parameter does not change the argument.
Local variables belonging to a method, as method calls generating, as a method for popping disappear.

Guess you like

Origin www.cnblogs.com/denglulu/p/12124908.html