1+2+3+4+5+6+7+8+9+n java 不用 if while for等关键字

来源:互联网 发布:linux本地安装包 编辑:程序博客网 时间:2024/06/10 09:24
public class T2 {public static int sum = 0;public static boolean add(int n) {sum += n;// 返回值用boolean,利用&&短路,避免了if判断return n != 1 && add(n - 1);}public static void main(String[] args) {add(100);System.out.println(T2.sum);}}


个人博客: bingtel-木犹如此的博客, 有兴趣可以关注下



0 0
原创粉丝点击