- import java.util.Arrays;
- public class Test {
- public static void main(String[] args) {
- int a = 3;
- int b = 4;
- System.out.println(a + "==" + b);
- inteter(a, b);// 基本类型 形参的改变对实参没有印象
- System.out.println(a + "==" + b);
- int[] arr = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
- System.out.println(Arrays.toString(arr));
- array(arr);// 传引用类型 形参的改变对实参有影响
- System.out.println(Arrays.toString(arr));
- }
- private static void inteter(int a, int b) {
- a = 6;
- b = 7;
- }
- private static void array(int[] arr) {
- for (int i = 0; i < arr.length; i++) {
- if (arr[i] % 2 == 0) {
- arr[i] *= 2;
- }
- }
- }
- }
复制代码 |