BonjourFFF 2010-03-28
1+2+3+...+100的结果:
public class Test {
int sum=0;
int a=1;
public void sum()
{
sum+=a;
a+=1;
if(a<=100)
{
sum();//调用自身实现递归
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Test test=new Test();
test.sum();
System.out.println("计算结果:"+test.sum+"!");
}