java-12.求 1+2+3+..n不能使用乘除法、 for 、 while 、 if 、 else 、 switch 、 case 等关键字以及条件判断语句
借鉴网上的思路,用java实现:
public class NoIfWhile {/** * @param args * * find x=1+2+3+....n */public static void main(String[] args) {int n=10;int re=find(n);System.out.print(re);}static int find(int n){int re=0;boolean whatever=false;int a=-1;whatever=(n!=0)&&(a==(re=find(n-1)));return re+n;}}