1 package day5;
2
3 /**
4 * @author haifei
5 *
6 * 方法的参数传递
7 *
8 */
9
10 public class demo3 {
11 public static void main(String[] args) {
12 //对于基本数据类型的参数,形式参数的改变,不影响实际参数
13 int num = 100;
14 System.out.println(num); //100
15 change(num);
16 System.out.println(num); //100
17
18 //对于引用类型的参数,形式参数的改变,影响实际参数的值
19 int[] arr = {10, 20, 30};
20 System.out.println(arr[1]); //20
21 change1(arr);
22 System.out.println(arr[1]); //200
23 }
24
25 public static void change(int num){
26 num = 200;
27 }
28
29 public static void change1(int[] arr){
30 arr[1] = 200;
31 }
32
33 }