(1). Find: the value of 1*2*3*4*5.......*n
- package suanfa;
- /**
- * Created by tl on 2016/4/10.
- */
- public class Digui {
- public static int digui ( int n) {
- if(n==1||n==0){
- return n;
- }else{
- System.out.println( "Execute " + n + " times" );
- return n * digui (n- 1 );
- }
- }
- publicstaticvoid main (String[] args){
- System.out.print(digui(n));
- }
(2). Find the value of 1+2+3+4+5...+n
- staticint count(int n){
- if(n>0){
- return n+count(n-1);
- }else{
- return0;
- }
- }
- publicstaticvoid main(String args[])
- {
- int sum=count(n);
- System.out.println(sum);
- }
- }
(3). Find the value of 1,1,2,3,5,8,13,21,34 .....n bits
- staticint count(int n){
- if(n==1||n==2) {
- return1;
- }
- return count(n-1)+count(n-2);
- }
- publicstaticvoid main(String args[])
- {
- int sum=count(n);
- System.out.println(sum);
- }