首页 > 技术文章 > java基础(参数传递)

sunda847882651 2018-08-21 19:36 原文

//参数传递:1.如果参数是基本数据类型,方法中参数的值改了,方法外参数还是原来的参数
//      2.如果参数是数组,方法中参数的值改了,方法外的参数值也改了

public class Demo {
static int a = 10;//基本数据类型
static int  [ ] b = {10};//数组
public static void main(String[] args) {
haha(a);
System.out.println(a);//结果是10
System.out.println("--------");
hehe(b);
System.out.println(b[0]);//结果是30
}

public static void haha(int a) {
a = a * 3;
}

public static void hehe(int[]b) {
b[0] = b[0] * 3;
}

}

推荐阅读