如题:
请实现一个方法得到两数相加结果,可用以下两种调用方式:
sum(2,3)输出5
sum(2)(3)输出5
sum(2)(3)(4) 输出9
```
package fuck;
class main {
public static void main(String[] args) {
Sum sum = new Sum();
sum.Sum(2, 3).Sum(2).Sum(2, 3);
}
}
class Sum {
public int total;
public Sum Sum(int... x) {
// Sum x = new Sum(x);
for (int v : x) {
this.total += v;
}
System.out.println(this.total);
return this;
}
}
```
贴个java版本吧,味道好像不太一样
#16
更多评论