day05-基本类型与引用类型作为方法参数的区别_debug说明

This commit is contained in:
2026-07-18 16:55:11 +08:00
parent 662dd86dd8
commit 2f68771628
2 changed files with 38 additions and 0 deletions
+22
View File
@@ -0,0 +1,22 @@
package com.inmind.array01;
/*
基本类型与引用类型作为方法参数的区别_debug说明
基本数据类型:保存具体的值,值传递
引用数据类型:保存地址值,址传递
*/
public class Demo08 {
public static void main(String[] args) {
int a = 10;
int b = 20;
changValue(a,b);
System.out.println(a);//10
System.out.println(b);//20
}
//基本数据类型作为参数,保存具体的值,值传递
public static void changValue(int a,int b) {
a = a+a;
b = b+b;
}
}
+16
View File
@@ -0,0 +1,16 @@
package com.inmind.array01;
public class Demo09 {
public static void main(String[] args) {
int[] arr = {10, 20};
changValue(arr);
System.out.println(arr[0]);//20
System.out.println(arr[1]);//40
}
//引用数据类型作为参数,保存具体的地址,址传递
public static void changValue(int[] arr) {
arr[0] = arr[0] + arr[0];
arr[1] = arr[1] + arr[1];
}
}