标签:scanner print iba pack exit sys else generated opd
package 汉尼拔;
import java.util.*;
public class 汉尼拔
{
static Scanner sc=new Scanner(System.in);
static int disk=sc.nextInt();
public static void main(String[] args)
{
// TODO Auto-generated method stub
Hannibal(disk,‘A‘,‘B‘,‘C‘);
System.exit(0);
}
public static void Hannibal(int Topdisk,char A,char B,char C)
{
if(Topdisk==1)
System.out.println("盘子 1 从 "+A+" 到"+C);
else
{
Hannibal(Topdisk-1,A,C,B);
System.out.println("盘子 "+Topdisk+" 从 "+A+" 到"+C);
Hannibal(Topdisk-1,B,A,C);
}
}
}
标签:scanner print iba pack exit sys else generated opd
原文地址:http://www.cnblogs.com/ljl1998/p/7712134.html