递归方法 求 数组和 -- 写法
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int [] arr = new int [n]; for(int i = 0;i < arr.length;i++) { arr[i] = sc.nextInt(); } System.out.print(add_Arr(arr,arr.length-1)); } public static int add_Arr(int [] arr,int n) { if(n == 0) { return arr[0]; }else { return arr[n] + add_Arr(arr,n-1); } } }