publicclassMethod{publicstaticvoidmain(String[] args){int a =10;int b =20;System.out.println("第一次调用方法之前");int ret =add(a, b);//30System.out.println("第一次调用方法之后");System.out.println("ret = "+ ret);System.out.println("第二次调用方法之前");
ret =add(30,50);//80System.out.println("第二次调用方法之后");System.out.println("ret = "+ ret);}publicstaticintadd(int x,int y){System.out.println("调用方法中 x = "+ x +" y = "+ y);return x + y;}}
//交换两个数的值publicclassTestMethod{publicstaticvoidmain(String[] args){int a =10;int b =20;swap(a, b);System.out.println("main: a = "+ a +" b = "+ b);}publicstaticvoidswap(int x,int y){int tmp = x;
x = y;
y = tmp;System.out.println("swap: x = "+ x +" y = "+ y);}}//结果,无法进行交换,因为形参和实参没有关系.改变了xy,也不会改变ab
classTest{publicstaticvoidmain(String[] args){int a =10;int b =20;print(a, b);}publicstaticvoidprint(int x,int y){System.out.println("x = "+ x +" y = "+ y);}}