对于基本数据类型的参数,形式参数的改变,不影响实际参数的值
package com.itheima;
import java.util.Scanner;
public class OperatorDemo {
public static void main(String[] args) {
int number = 100;
System.out.println("修改前" + number);
//形式参数的改变,不会影响实际参数的值
change(number);
System.out.println("修改后" + number);
}
public static void change(int number){
number = 200;
}
}
对于应用类型的参数,形式参数的改变,影响实际参数的值
package com.itheima;
import java.util.Scanner;
public class OperatorDemo {
public static void main(String[] args) {
int[] arr = {10,20,30};
System.out.println("调用前:"+arr[1]);
change(arr);
System.out.println("调用后"+arr[1]);
}
public static void change(int[] arr) {
arr[1] = 200;
}
}
System.out.println("内容"); //输出内容并换行
System.out.print("内容");? //输出内容不换行
System.out.print(); //换行
输出[1,2,3,4,5,6,7,8,9]
package com.itheima;
import java.util.Scanner;
public class OperatorDemo {
public static void main(String[] args) {
int [] arr = {1,2,3,4,5,6,7,8,9};
printArry(arr);
}
public static void printArry(int[] arr){
System.out.print("[");
for (int x=0;x<arr.length;x++){
if (x == arr.length-1) {
System.out.print(arr[x]);
} else {
System.out.print(arr[x]+",");
}
}
System.out.print("]");
}
}
debug通过idea查看
?
?
?
?
|