
题目
求1+2+3+…+n,要求不能使用乘除法、for、while、if、else、switch、case等关键字及条件判断语句(A?B:C)。
解题思路
不能循环就递归实现
不能if就条件判断使用 && 实现
1 2 3 4 5 6 7 8 9
|
public class { public int Sum_Solution(int n) { int res = n; boolean x = (res > 0) && ((res += Sum_Solution(n - 1)) > 0); return res; } }
|
近期评论