1,递归调用的使用
/*递归调用四条基本法则:
* 1,基准情形:必须有某些基准情形,他们不用递归就能求解* 2,不断推进:对于那些需要递归求解的情形,递归调用总能够朝着基准的情形的方向走过去
* 3,设计法则:假设所有的地柜都能调用
* 4,和成效益法则:再求解一个问题的同一实例时,切勿在不同的递归中做重复的运算
* */
package Demo1;
public class DiGui {
void printOut(int n){
if(n>=10)
printOut(n/10);//该步执行完了,继续执行下一步,所以可以把每个数字都打印出来
System.out.print(n%10);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
DiGui d = new DiGui();
d.printOut(123);
//Integer i = new Integer("321");System.out.println(i);
}
}
2,调用自身构造方法
package Demo1;
public class DuiGui_2 {
public static void main(String[] args) {
IntCell iCell=new IntCell(10);
iCell.write(20);
System.out.println("get the value:"+iCell.read());
}
}
class IntCell{
private int storedValue;
public IntCell(){
this(0);//调用自身的有参数构造方法,
}
public IntCell(int initialValue){
this.storedValue=initialValue;
}
public int read(){
return storedValue;
}
public void write(int x){
storedValue=x;
}
}