public class Hanoi {
public static void main(String args[]) throws IOException {
BufferedReader buf = new BufferedReader(
new InputStreamReader(System.in));
System.out.print("请输入盘数:");
int n = Integer.parseInt(buf.readLine());
Hanoi hanoi = new Hanoi();
hanoi.move(n, 'A', 'B', 'C');
}
public void move(int n, char a, char b, char c) {
if (n == 1)
System.out.println("第" + n + "个盘由" + a + "移至" + c);
else {
move(n - 1, a, c, b);
System.out.println("第" + n + "个盘由" + a + "移至" + c);
move(n - 1, b, a, c);
}
}
} 作者: x378320002 时间: 2013-7-7 21:57
楼主这是自己想的代码么?巨牛啊