---
title: "递归实现加法"
author: "alovejun14"
date: "2010-08-27T20:35:01Z"
tags: []
categories: ["编程语言"]
slug: "untitled"
draft: false
lastmod: "2010-08-27T20:35:01Z"
id: 749341
url: "https://alovejun14.iteye.com/blog/749341"
---

01. **public** **class** SumPlus
02. {
03. **public** **static** **void** main(String args\[])
04. {
05. **int**\[] num = **new** **int**\[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
06. **int** x = 10;
07. SumPlus test = **new** SumPlus();
08. System.out.println(test.sum(num, x));
09. }
10. **public** **int** sum(**int**\[] num, **int** n)
11. {
12. **if** (n &gt; 0)
13. {
14. **return** num\[n - 1] + sum(num, n - 1);
15. }
16. **else**
17. **return** 0;
18. }
19. }