Lab Recursive Method
package s9325116;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class recursion {
public static void main(String[] args)throws IOException
{ BufferedReader keyboard=new BufferedReader(new InputStreamReader(System.in));
int b=Integer.parseInt(keyboard.readLine());
int c=recursive(b);
System.out.println(c);
}
public static int recursive(int n)
{
if(n==1)
return 1;
else
return recursive(n-1)+n*n;
}
}
-------------------------------------------------------------------------------------------------
執行結果
222
3671695
0 Comments:
发表评论
<< Home