day05-基本数据类型与引用数据类型作为参数的区别
This commit is contained in:
27
day05/src/com/inmind/Demo07.java
Normal file
27
day05/src/com/inmind/Demo07.java
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
package com.inmind;
|
||||||
|
/*
|
||||||
|
基本数据类型作为方法参数的操作
|
||||||
|
断点:break point
|
||||||
|
断点使用:在要调用的方法的第一行,点上断点
|
||||||
|
F8:向下执行一行代码
|
||||||
|
F7:进入方法中
|
||||||
|
shift+F8:跳出方法
|
||||||
|
|
||||||
|
注意:基本数据类型作为方法参数,是直接传递具体的值,它是不会影响原本方法中的变量的值的!!!!
|
||||||
|
*/
|
||||||
|
public class Demo07 {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
int a = 10;
|
||||||
|
int b = 20;
|
||||||
|
//修改值
|
||||||
|
changeValue(a,b);
|
||||||
|
System.out.println(a);
|
||||||
|
System.out.println(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
//方法
|
||||||
|
public static void changeValue(int a, int b) {
|
||||||
|
a = a+a;
|
||||||
|
b = b+b;
|
||||||
|
}
|
||||||
|
}
|
||||||
18
day05/src/com/inmind/Demo08.java
Normal file
18
day05/src/com/inmind/Demo08.java
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
package com.inmind;
|
||||||
|
/*
|
||||||
|
引用类型作为方法参数:传递的是地址!!!!
|
||||||
|
*/
|
||||||
|
public class Demo08 {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
//定义一个数组
|
||||||
|
int[] arr = {10,20};
|
||||||
|
changValue(arr);
|
||||||
|
System.out.println(arr[0]);//
|
||||||
|
System.out.println(arr[1]);//
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void changValue(int[] arr) {
|
||||||
|
arr[0] = arr[0] + arr[0];
|
||||||
|
arr[1] = arr[1] + arr[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user