不知道 你想问什么,所以把结果的原因都弄出来了,不懂的再问好了
- import java.util.*;
- class ArgsDemo {
- public static void main(String[] args) {
- int a = 10;
- int b = 20;
- System.out.println(a+"---"+b);//10---20
- change(a,b);
- System.out.println(a+"---"+b);
- int[] arr = {1,2,3,4,5};
- change(arr);
- System.out.println(arr[1]); //arr[1]=4
- }
- public static void change(int a,int b) {
- System.out.println(a+"---"+b); //10---20
- a = b; //b覆盖a ,a=20 b=20
- b = a + b; //b=40
- System.out.println(a+"---"+b); //20---40
- }
- public static void change(int[] arr) {
- for(int x=0; x<arr.length; x++) {
- if(arr[x]%2==0) {
- arr[x]*=2; //arr[1] = arr[1] * 2 ,得到4
- }
- }
- }
- }
复制代码 |