求1+2+3+…+n,要求不能使用乘除法、for、while、if、else、switch、case等关键字及条件判断语句(A?B:C)
public static int sum_solution1(int n) {
int sum = n;
//boolean b = (n > 0) && (sum += sum_solution1(n-1)) > 0;
boolean b = (n == 0) || (sum += sum_solution1(n - 1)) > 0;
return sum;
}
public
转载
2017-06-20 15:04:04 ·
688 阅读 ·
0 评论