"Lab Recursive Method"
package s9226307;public class s9226307 {
public static void main(String[] args) {
System.out.println(""+recursive(3,1,2,3));
}
public static int recursive(int n,int src,int aux,int des)
{
if(n==1)
{
System.out.println("Move " +1+ " from " +src+ " to "+des);
}
else
{
recursive(n-1, src, des, aux);
System.out.println("Move " +n+ " from " +src+ " to "+des);
recursive(n - 1, aux, src, des);
}
return 0;
}
}
0 Comments:
Post a Comment
<< Home