(程序輸出結(jié)果是移動(dòng)路徑)
熱心網(wǎng)友
import 。*;public class Towers{static int nDisks;public static void main(String[] args) throws IOException{ intln("請(qǐng)輸入盤子的個(gè)數(shù):");nDisks= rseInt(In());doTowers(nDisks,'A','B','C');}public static void doTowers(int topN,char A,char B,char C){if(topN==1) intln("Disk 1 form "+A+" to "+C);else{doTowers(topN-1,A,C,B);//把A上的N-1個(gè)盤子放到B上 intln("Disk "+topN+" from "+A+" to "+C);doTowers(topN-1,B,A,C);//把B撒謊那個(gè)的N-1個(gè)盤子放到c上}}public static String In() throws IOException{String str;BufferedReader Input=new BufferedReader(new InputStreamReader( ));//數(shù)據(jù)流進(jìn)行輸入str= adLine();//讀取行。return str;}}。