Lab16
public class recursive {
public static void main(String[] args)
{
recursive(3,1,2,3);
}
public static void recursive (int i,int one,int two,int three ){
if(i==1) {
System.out.println("Move dis"+1+" From "+one+" to "+three);
}
else{
recursive ( i-1, one, three, two );
System.out.println("Move dis"+i+" From "+one+" to "+three);
recursive ( i-1, two, one, three );
}}}
結果:
public static void main(String[] args)
{
recursive(3,1,2,3);
}
public static void recursive (int i,int one,int two,int three ){
if(i==1) {
System.out.println("Move dis"+1+" From "+one+" to "+three);
}
else{
recursive ( i-1, one, three, two );
System.out.println("Move dis"+i+" From "+one+" to "+three);
recursive ( i-1, two, one, three );
}}}
結果:
0 Comments:
張貼留言
<< Home