1.计算阶乘
1 public static int factorialCalculation(int m){ 2 if(m>1){ 3 return m*factorialCalculation( m-1 ) 4 }else{ 5 return 1; 6 } 7 }
整个结构是“V”字型,注意递归函数调用的终止
2.两个数的交换
1 public class MyNumber{ 2 private int num; 3 public MyNumber(){return num;}
4 5 MyNumber obj1 = new MyNumber(); 6 MyNumber obj2 = new MyNumber(); 7 8 public static void swap(MyNumber obj3, MyNumber obj4) 9 { 10 int s = obj3.num; 11 obj.num = obj4.num 12 obj4.num = s; 13 } 14 }