[上]JAVA学习系列模块六第二章138.方法_数组作为方法返回值返回
视频
笔记
练习7
数组作为返回值返回
public class Demo05Method { public static void main(String[] args) { int[] arr2 = method();//int[] arr2 = arr1 for (int i = 0; i < arr2.length; i++) { System.out.println(arr2[i]); } } public static int[] method(){ int a = 10; int b = 20; int sum = a+b; int sub = a-b; int[] arr1 = {sum,sub}; return arr1;//返回的是一个int[],那么返回值类型也应该是int[] } }