網頁

2016年11月30日 星期三

ex12 河內塔



河內塔程式

61 則留言:

  1. public class ex1 {
    static int N=0;
    static void hanoi(char A,char B,char C,int n){
    if (n==1)
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    else{
    hanoi(A,C,B,n-1);
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    hanoi(B,A,C,n-1);
    }
    }
    public static void main(String[] args) {
    hanoi('A','B','C',5);

    }

    }

    回覆刪除
  2. package hello;

    public class ex01 {
    static int N=0;
    static void hanoi(char A,char B,char C,int n){
    if(n==1)
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    else{
    hanoi(A,B,C,n-1);
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    hanoi(A,B,C,n-1);
    }
    }

    public static void main(String[] args) {
    hanoi('A','B','C',5);

    }

    }

    回覆刪除
  3. public class ex01 {
    static int N=0;
    static void hanoi (char A, char B, char C, int n){
    if (n==1)
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    else{
    hanoi(A,C,B, n-1);
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    hanoi(B,A,C, n-1);
    }
    }

    public static void main(String[] args) {
    hanoi('A','B','C', 5);

    }
    }

    回覆刪除
  4. package hello;

    public class ex01 {
    static int N=0;
    static void hanoi(char A,char B,char C,int n){
    if(n==1)
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    else{
    hanoi(A,B,C,n-1);
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    hanoi(A,B,C,n-1);
    }
    }

    public static void main(String[] args) {
    hanoi('A','B','C',5);

    }

    }

    回覆刪除
  5. public class ex1 {
    static int N=0;
    static void hanoi(char A,char B,char C,int n){
    if(n==1)
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    else{
    hanoi(A,C,B,n-1);
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    hanoi(B,A,C,n-1);
    }
    }
    public static void main(String[] args) {
    hanoi('A','B','C',5);
    }
    }

    回覆刪除
  6. package hello;

    public class ex01 {
    static int N=0;
    static void hanoi(char A,char B,char C,int n){
    if(n==1)
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    else{
    hanoi(A,B,C,n-1);
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    hanoi(A,B,C,n-1);
    }
    }

    public static void main(String[] args) {
    hanoi('A','B','C',5);

    }

    }

    回覆刪除
  7. public class hello {
    static int N=0;
    static void hanoi (char A, char B, char C , int n){
    if (n==1)
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    else{
    hanoi(A, C, B, n-1);
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    hanoi(B, A, C, n-1);
    }
    }
    public static void main(String[] args) {
    hanoi('A','B','C', 4);

    }

    }

    回覆刪除
  8. package p1;

    public class hw1 {
    static int N=0;
    static void hanoi(char A,char B,char C,int n){
    if (n==1)
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    else{
    hanoi(A,C,B,n-1);
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    hanoi(A,C,B,n-1);
    }
    }
    public static void main(String[] args) {
    hanoi('A','B','C',5);
    }

    }

    回覆刪除
  9. package p1;

    public class hw1 {
    static int N=0;
    static void hanoi(char A, char B, char C, int n){
    if(n==1)
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    else{
    hanoi(A,C,B,n-1);
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    hanoi(B,A,C,n-1);
    }
    }

    public static void main(String[] args) {
    hanoi('A','B','C',5);


    }

    }

    回覆刪除
  10. public class hello {
    static int N=0;
    static void hanoi (char A, char B, char C, int n){
    if (n==1)
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    else{
    hanoi(A,C,B,n-1);
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    hanoi(A,C,B,n-1);
    }
    }
    public static void main(String[] args) {
    hanoi('A','B','C',5);
    }
    }

    回覆刪除
  11. public class ex01
    {
    static int N=0;
    static void hanoi(int A,int B,int C,int n)
    {
    if (n==1)
    System.out.println("移動"+n+":"+A+"=>"+C);
    else
    {
    hanoi(A,C,B,n-1);
    System.out.println("移動"+n+":"+A+"=>"+C);
    hanoi(B,A,C,n-1);
    }
    }
    public static void main(String[] args)
    {
    hanoi(1,2,3,4);
    }

    }

    回覆刪除
  12. B10433188 姜佩萱(新的留言)2016年11月30日 上午10:42

    public class hello {
    static int N=0;
    static void hanoi (char A, char B, char C , int n){
    if (n==1)
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    else{
    hanoi(A, C, B, n-1);
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    hanoi(B, A, C, n-1);
    }
    }
    public static void main(String[] args) {
    hanoi('A','B','C', 4);

    }

    }

    回覆刪除
  13. public class ex12 {
    static int N=0;
    static void hanoi(char A, char B, char C, int n){
    if(n==1)
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    else{
    hanoi(A,C,B,n-1);
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    hanoi(B,A,C,n-1);
    }
    }
    public static void main(String[] args) {
    hanoi('A','B','C',4);
    }
    }

    回覆刪除
  14. public class a01 {
    static int N=0;
    static void Hn(char A,char B,char C,int n){
    if(n==1)System.out.println("第"+(++N)+"步:\t"+n+"從"+A+"->"+C);
    else{
    Hn(A,C,B,n-1);
    System.out.println("第"+(++N)+"步:\t"+n+"從"+A+"->"+C);
    Hn(B,A,C,n-1);
    }
    }
    public static void main(String[] args) {
    Hn('A','B','C',4);
    }
    }
    第1步: 1從A->B
    第2步: 2從A->C
    第3步: 1從B->C
    第4步: 3從A->B
    第5步: 1從C->A
    第6步: 2從C->B
    第7步: 1從A->B
    第8步: 4從A->C
    第9步: 1從B->C
    第10步: 2從B->A
    第11步: 1從C->A
    第12步: 3從B->C
    第13步: 1從A->B
    第14步: 2從A->C
    第15步: 1從B->C

    回覆刪除
  15. public class hello {
    static int N=0;
    static void hanoi(char A, char B, char C, int n){
    if (n==1)
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    else{
    hanoi(A, C, B, n-1);
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    hanoi(B, A, C, n-1);
    }
    }
    public static void main(String[] args) {
    hanoi('A','B','C', 5);

    }

    }

    回覆刪除
  16. package p1;

    public class ex01 {

    static int N=0;
    static void hanoi(char A, char B, char C, int n){
    if (n==1)
    System.out.println((++N)+":移動" +n +":" +A+"=>"+C);
    else{
    hanoi(A,C,B,n-1);
    System.out.println((++N)+":移動" +n +":" +A+"=>"+C);
    hanoi(B,A,C, n-1);
    }

    }
    public static void main(String[] args)
    {
    hanoi('A','B','C', 5);
    }
    }

    回覆刪除
  17. public class hello {
    static int N=0;
    static void hanoi (char A, char B, char C , int n){
    if (n==1)
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    else{
    hanoi(A, C, B, n-1);
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    hanoi(B, A, C, n-1);
    }
    }
    public static void main(String[] args) {
    hanoi('A','B','C', 4);

    }

    }

    回覆刪除

  18. public class Ex12 {
    static int N=0;
    static void hanoi(char A, char B, char C, int n){
    if (n==1)
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    else{
    hanoi(A, C, B, n-1);
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    hanoi(B, A, C, n-1);
    }
    }
    public static void main(String[] args) {
    hanoi('A','B','C',5);
    }

    }

    回覆刪除
  19. public class hello {
    static int N=0;
    static void hanoi (char A, char B, char C , int n){
    if (n==1)
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    else{
    hanoi(A, C, B, n-1);
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    hanoi(B, A, C, n-1);
    }
    }
    public static void main(String[] args) {
    hanoi('A','B','C', 4);

    }

    }

    回覆刪除
  20. package ererer;

    public class ex1 {
    static int N=0;
    public static void hanoi(int A,int B,int C ,int n) {
    if(n==1)
    System.out.println((++N)+":移動"+N+":"+A+"=>"+C);
    else{
    hanoi(A,C,B,n-1);
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    hanoi(B,A,C,n-1);
    }
    }
    public static void main(String[] args) {
    hanoi(1,2,3,4);
    }
    }

    回覆刪除
  21. public class hello {
    static int N=0;
    static void hanoi (char A, char B, char C , int n){
    if (n==1)
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    else{
    hanoi(A, C, B, n-1);
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    hanoi(B, A, C, n-1);
    }
    }
    public static void main(String[] args) {
    hanoi('A','B','C', 4);

    }

    }

    回覆刪除
  22. package ererer;

    public class ex1 {
    static int N=0;
    public static void hanoi(int A,int B,int C ,int n) {
    if(n==1)
    System.out.println((++N)+":移動"+N+":"+A+"=>"+C);
    else{
    hanoi(A,C,B,n-1);
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    hanoi(B,A,C,n-1);
    }
    }
    public static void main(String[] args) {
    hanoi(1,2,3,4);
    }
    }

    回覆刪除
  23. package ererer;

    public class ex1 {
    static int N=0;
    public static void hanoi(int A,int B,int C ,int n) {
    if(n==1)
    System.out.println((++N)+":移動"+N+":"+A+"=>"+C);
    else{
    hanoi(A,C,B,n-1);
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    hanoi(B,A,C,n-1);
    }
    }
    public static void main(String[] args) {
    hanoi(1,2,3,4);
    }
    }

    回覆刪除
  24. package hello;
    public class hello {
    static int N=0;
    static void hanoi(char A, char B, char C,int n){
    if (n==1)
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    else{
    hanoi(A,B,C, n-1);
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    hanoi(B,A,C, n-1);
    }
    }

    public static void main(String[] args) {
    hanoi('A','B','C', 5);
    }
    }

    回覆刪除
  25. package ddt;

    public class ttd {
    static int N=0;

    public static void hanoi(int A,int B,int C,int n)
    {
    if(n==1)
    System.out.println((++N)+":移動"+N+":"+A+"=>"+C);
    else
    {
    hanoi(A,C,B,n-1);
    System.out.println((++N)+":移動"+N+":"+A+"=>"+C);
    hanoi(B,C,A,n-1);
    }
    }

    public static void main(String[] args) {

    hanoi(1,2,3,4);


    }

    }

    回覆刪除
  26. package hello;
    public class hello{
    static int N=0;
    static void hanoi(int A,int B, int C, int n){
    if (n==1)
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    else
    {
    hanoi(A , C, B, n-1);
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    hanoi(B , A, C, n-1);
    }
    }

    public static void main (String[] args){
    hanoi (1,2,3, 4);
    }
    }

    ------------------------------------
    1:移動1:1=>2
    2:移動2:1=>3
    3:移動1:2=>3
    4:移動3:1=>2
    5:移動1:3=>1
    6:移動2:3=>2
    7:移動1:1=>2
    8:移動4:1=>3
    9:移動1:2=>3
    10:移動2:2=>1
    11:移動1:3=>1
    12:移動3:2=>3
    13:移動1:1=>2
    14:移動2:1=>3
    15:移動1:2=>3


    回覆刪除
  27. package hello;
    public class hello{
    static int N=0;
    static void hanoi(int A,int B, int C, int n){
    if (n==1)
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    else
    {
    hanoi(A , C, B, n-1);
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    hanoi(B , A, C, n-1);
    }
    }

    public static void main (String[] args){
    hanoi (1,2,3, 4);
    }
    }

    ------------------------------------
    1:移動1:1=>2
    2:移動2:1=>3
    3:移動1:2=>3
    4:移動3:1=>2
    5:移動1:3=>1
    6:移動2:3=>2
    7:移動1:1=>2
    8:移動4:1=>3
    9:移動1:2=>3
    10:移動2:2=>1
    11:移動1:3=>1
    12:移動3:2=>3
    13:移動1:1=>2
    14:移動2:1=>3
    15:移動1:2=>3


    回覆刪除
  28. package hello;
    public class hello{
    static int N=0;
    static void hanoi(int A,int B, int C, int n){
    if (n==1)
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    else
    {
    hanoi(A , C, B, n-1);
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    hanoi(B , A, C, n-1);
    }
    }

    public static void main (String[] args){
    hanoi (1,2,3, 4);
    }
    }

    ------------------------------------
    1:移動1:1=>2
    2:移動2:1=>3
    3:移動1:2=>3
    4:移動3:1=>2
    5:移動1:3=>1
    6:移動2:3=>2
    7:移動1:1=>2
    8:移動4:1=>3
    9:移動1:2=>3
    10:移動2:2=>1
    11:移動1:3=>1
    12:移動3:2=>3
    13:移動1:1=>2
    14:移動2:1=>3
    15:移動1:2=>3


    回覆刪除
  29. package hello;
    public class hello{
    static int N=0;
    static void hanoi(int A,int B, int C, int n){
    if (n==1)
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    else
    {
    hanoi(A , C, B, n-1);
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    hanoi(B , A, C, n-1);
    }
    }

    public static void main (String[] args){
    hanoi (1,2,3, 4);
    }
    }

    ------------------------------------
    1:移動1:1=>2
    2:移動2:1=>3
    3:移動1:2=>3
    4:移動3:1=>2
    5:移動1:3=>1
    6:移動2:3=>2
    7:移動1:1=>2
    8:移動4:1=>3
    9:移動1:2=>3
    10:移動2:2=>1
    11:移動1:3=>1
    12:移動3:2=>3
    13:移動1:1=>2
    14:移動2:1=>3
    15:移動1:2=>3


    回覆刪除
  30. package hw1;

    public class hello {
    static int N=0;
    static void hanoi(char A, char B, char C, int n){
    if (n==1)
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    else{
    hanoi(A, C, B, n-1);
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    hanoi(B, A, C, n-1);
    }
    }
    public static void main(String[] args) {
    hanoi('A','B','C', 5);

    }

    }

    回覆刪除
  31. package hello;
    public class hello{
    static int N=0;
    static void hanoi(int A,int B, int C, int n){
    if (n==1)
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    else
    {
    hanoi(A , C, B, n-1);
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    hanoi(B , A, C, n-1);
    }
    }

    public static void main (String[] args){
    hanoi (1,2,3, 4);
    }
    }

    ------
    1:移動1:1=>2
    2:移動2:1=>3
    3:移動1:2=>3
    4:移動3:1=>2
    5:移動1:3=>1
    6:移動2:3=>2
    7:移動1:1=>2
    8:移動4:1=>3
    9:移動1:2=>3
    10:移動2:2=>1
    11:移動1:3=>1
    12:移動3:2=>3
    13:移動1:1=>2
    14:移動2:1=>3
    15:移動1:2=>3


    回覆刪除
  32. package hello;
    public class hello{
    static int N=0;
    static void hanoi(int A,int B, int C, int n){
    if (n==1)
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    else
    {
    hanoi(A , C, B, n-1);
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    hanoi(B , A, C, n-1);
    }
    }

    public static void main (String[] args){
    hanoi (1,2,3, 4);
    }
    }






    1:移動1:1=>2
    2:移動2:1=>3
    3:移動1:2=>3
    4:移動3:1=>2
    5:移動1:3=>1
    6:移動2:3=>2
    7:移動1:1=>2
    8:移動4:1=>3
    9:移動1:2=>3
    10:移動2:2=>1
    11:移動1:3=>1
    12:移動3:2=>3
    13:移動1:1=>2
    14:移動2:1=>3
    15:移動1:2=>3


    回覆刪除
  33. public class EX01 {
    static int N=0;

    static void hanoi(char A,char B,char C,int n){
    if (n==1)
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    else{
    hanoi(A,C,B,n-1);
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    hanoi(B,A,C,n-1);

    }
    }
    public static void main(String[]args){
    hanoi('A','B','C',5);
    }
    }

    回覆刪除
  34. public class ex {
    static int N=0;
    static void hanoi(int A, int B, int C, int n){
    if (n==1)
    System.out.println((++N)+"移動"+n+": "+A+"=>"+C);
    else {
    hanoi (A,C,B,n-1);
    System.out.println((++N)+"移動"+n+": "+A+"=>"+C);
    hanoi(B,A,C,n-1);
    }
    }
    public static void main(String[] args) {
    hanoi(1,2,3, 1000);
    }
    }

    回覆刪除
  35. public class ex01 {

    static int N=0;

    public static void hanoi(int A, int B,int C,int n) {

    if (n==1)

    System.out.println((++N)+"步 "+"移動"+n+"層"+":"+A+"柱=>"+C+"柱");

    else{

    hanoi(A,C,B,n-1);

    System.out.println((++N)+"步 "+"移動"+n+"層"+":"+A+"柱=>"+C+"柱");

    hanoi(B,A,C,n-1);

    }

    }

    public static void main(String[] args){

    hanoi(1,2,3,4);

    }



    }

    回覆刪除
  36. package hello;
    public class hello{
    static int N=0;
    static void hanoi(int A,int B, int C, int n){
    if (n==1)
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    else
    {
    hanoi(A , C, B, n-1);
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    hanoi(B , A, C, n-1);
    }
    }

    public static void main (String[] args){
    hanoi (1,2,3, 4);
    }
    }

    ------------------------------------
    1:移動1:1=>2
    2:移動2:1=>3
    3:移動1:2=>3
    4:移動3:1=>2
    5:移動1:3=>1
    6:移動2:3=>2
    7:移動1:1=>2
    8:移動4:1=>3
    9:移動1:2=>3
    10:移動2:2=>1
    11:移動1:3=>1
    12:移動3:2=>3
    13:移動1:1=>2
    14:移動2:1=>3
    15:移動1:2=>3

    回覆刪除
  37. package hello;
    public class hello{
    static int N=0;
    static void hanoi(int A,int B, int C, int n){
    if (n==1)
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    else
    {
    hanoi(A , C, B, n-1);
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    hanoi(B , A, C, n-1);
    }
    }

    public static void main (String[] args){
    hanoi (1,2,3, 4);
    }
    }

    ------------------------------------
    1:移動1:1=>2
    2:移動2:1=>3
    3:移動1:2=>3
    4:移動3:1=>2
    5:移動1:3=>1
    6:移動2:3=>2
    7:移動1:1=>2
    8:移動4:1=>3
    9:移動1:2=>3
    10:移動2:2=>1
    11:移動1:3=>1
    12:移動3:2=>3
    13:移動1:1=>2
    14:移動2:1=>3
    15:移動1:2=>3

    回覆刪除
  38. package hello;
    public class hello{
    static int N=0;
    static void hanoi(int A,int B, int C, int n){
    if (n==1)
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    else
    {
    hanoi(A , C, B, n-1);
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    hanoi(B , A, C, n-1);
    }
    }

    public static void main (String[] args){
    hanoi (1,2,3, 4);
    }
    }

    ------------------------------------
    1:移動1:1=>2
    2:移動2:1=>3
    3:移動1:2=>3
    4:移動3:1=>2
    5:移動1:3=>1
    6:移動2:3=>2
    7:移動1:1=>2
    8:移動4:1=>3
    9:移動1:2=>3
    10:移動2:2=>1
    11:移動1:3=>1
    12:移動3:2=>3
    13:移動1:1=>2
    14:移動2:1=>3
    15:移動1:2=>3

    回覆刪除
  39. package hello;
    public class hello{
    static int N=0;
    static void hanoi(int A,int B, int C, int n){
    if (n==1)
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    else
    {
    hanoi(A , C, B, n-1);
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    hanoi(B , A, C, n-1);
    }
    }

    public static void main (String[] args){
    hanoi (1,2,3, 4);
    }
    }

    ------------------------------------
    1:移動1:1=>2
    2:移動2:1=>3
    3:移動1:2=>3
    4:移動3:1=>2
    5:移動1:3=>1
    6:移動2:3=>2
    7:移動1:1=>2
    8:移動4:1=>3
    9:移動1:2=>3
    10:移動2:2=>1
    11:移動1:3=>1
    12:移動3:2=>3
    13:移動1:1=>2
    14:移動2:1=>3
    15:移動1:2=>3

    回覆刪除
  40. public class Ex12 {
    static int N=0;
    static void hanoi(char A, char B, char C, int n){
    if (n==1)
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    else{
    hanoi(A, C, B, n-1);
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    hanoi(B, A, C, n-1);
    }
    }
    public static void main(String[] args) {
    hanoi('A','B','C',5);
    }

    }

    回覆刪除
  41. public class ex1 {
    static int N=0;
    static void hanoi(char A,char B,char C,int n){
    if (n==1)
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    else{
    hanoi(A,C,B,n-1);
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    hanoi(B,A,C,n-1);
    }
    }
    public static void main(String[] args) {
    hanoi('A','B','C',5);

    }

    }

    回覆刪除
  42. package hello;
    public class hello{
    static int N=0;
    static void hanoi(int A,int B, int C, int n){
    if (n==1)
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    else
    {
    hanoi(A , C, B, n-1);
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    hanoi(B , A, C, n-1);
    }
    }

    public static void main (String[] args){
    hanoi (1,2,3, 4);
    }
    }

    ------------------------------------
    1:移動1:1=>2
    2:移動2:1=>3
    3:移動1:2=>3
    4:移動3:1=>2
    5:移動1:3=>1
    6:移動2:3=>2
    7:移動1:1=>2
    8:移動4:1=>3
    9:移動1:2=>3
    10:移動2:2=>1
    11:移動1:3=>1
    12:移動3:2=>3
    13:移動1:1=>2
    14:移動2:1=>3
    15:移動1:2=>3

    回覆刪除
  43. package hello;
    public class hello{
    static int N=0;
    static void hanoi(int A,int B, int C, int n){
    if (n==1)
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    else
    {
    hanoi(A , C, B, n-1);
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    hanoi(B , A, C, n-1);
    }
    }

    public static void main (String[] args){
    hanoi (1,2,3, 4);
    }
    }

    ------------------------------------
    1:移動1:1=>2
    2:移動2:1=>3
    3:移動1:2=>3
    4:移動3:1=>2
    5:移動1:3=>1
    6:移動2:3=>2
    7:移動1:1=>2
    8:移動4:1=>3
    9:移動1:2=>3
    10:移動2:2=>1
    11:移動1:3=>1
    12:移動3:2=>3
    13:移動1:1=>2
    14:移動2:1=>3
    15:移動1:2=>3

    回覆刪除
  44. package hello;
    public class hello{
    static int N=0;
    static void hanoi(int A,int B, int C, int n){
    if (n==1)
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    else
    {
    hanoi(A , C, B, n-1);
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    hanoi(B , A, C, n-1);
    }
    }

    public static void main (String[] args){
    hanoi (1,2,3, 4);
    }
    }

    ------------------------------------
    1:移動1:1=>2
    2:移動2:1=>3
    3:移動1:2=>3
    4:移動3:1=>2
    5:移動1:3=>1
    6:移動2:3=>2
    7:移動1:1=>2
    8:移動4:1=>3
    9:移動1:2=>3
    10:移動2:2=>1
    11:移動1:3=>1
    12:移動3:2=>3
    13:移動1:1=>2
    14:移動2:1=>3
    15:移動1:2=>3

    回覆刪除
  45. B10233049 黃家崙2016年12月26日 下午2:35

    package hello;
    public class hello{
    static int N=0;
    static void hanoi(int A,int B, int C, int n){
    if (n==1)
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    else
    {
    hanoi(A , C, B, n-1);
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    hanoi(B , A, C, n-1);
    }
    }

    public static void main (String[] args){
    hanoi (1,2,3, 4);
    }
    }

    ------------------------------------
    1:移動1:1=>2
    2:移動2:1=>3
    3:移動1:2=>3
    4:移動3:1=>2
    5:移動1:3=>1
    6:移動2:3=>2
    7:移動1:1=>2
    8:移動4:1=>3
    9:移動1:2=>3
    10:移動2:2=>1
    11:移動1:3=>1
    12:移動3:2=>3
    13:移動1:1=>2
    14:移動2:1=>3
    15:移動1:2=>3

    回覆刪除
  46. B10433022 吳欣芸2016年12月26日 下午3:23

    public class ex1 {
    static int N=0;
    static void hanoi(char A,char B,char C,int n){
    if (n==1)
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    else{
    hanoi(A,C,B,n-1);
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    hanoi(B,A,C,n-1);
    }
    }
    public static void main(String[] args) {
    hanoi('A','B','C',5);

    }

    回覆刪除
  47. B10433040 葉峻宇2016年12月27日 下午5:40

    package hello;
    public class hello{
    static int N=0;
    static void hanoi(int A,int B, int C, int n){
    if (n==1)
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    else
    {
    hanoi(A , C, B, n-1);
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    hanoi(B , A, C, n-1);
    }
    }

    public static void main (String[] args){
    hanoi (1,2,3, 4);
    }
    }

    ------------------------------------
    1:移動1:1=>2
    2:移動2:1=>3
    3:移動1:2=>3
    4:移動3:1=>2
    5:移動1:3=>1
    6:移動2:3=>2
    7:移動1:1=>2
    8:移動4:1=>3
    9:移動1:2=>3
    10:移動2:2=>1
    11:移動1:3=>1
    12:移動3:2=>3
    13:移動1:1=>2
    14:移動2:1=>3
    15:移動1:2=>3

    回覆刪除
  48. package hello;
    public class hello{
    static int N=0;
    static void hanoi(int A,int B, int C, int n){
    if (n==1)
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    else
    {
    hanoi(A , C, B, n-1);
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    hanoi(B , A, C, n-1);
    }
    }

    public static void main (String[] args){
    hanoi (1,2,3, 4);
    }
    }

    ------------------------------------
    1:移動1:1=>2
    2:移動2:1=>3
    3:移動1:2=>3
    4:移動3:1=>2
    5:移動1:3=>1
    6:移動2:3=>2
    7:移動1:1=>2
    8:移動4:1=>3
    9:移動1:2=>3
    10:移動2:2=>1
    11:移動1:3=>1
    12:移動3:2=>3
    13:移動1:1=>2
    14:移動2:1=>3
    15:移動1:2=>3

    回覆刪除
  49. package hello;
    public class hello{
    static int N=0;
    static void hanoi(int A,int B, int C, int n){
    if (n==1)
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    else
    {
    hanoi(A , C, B, n-1);
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    hanoi(B , A, C, n-1);
    }
    }

    public static void main (String[] args){
    hanoi (1,2,3, 4);
    }
    }

    ------------------------------------
    1:移動1:1=>2
    2:移動2:1=>3
    3:移動1:2=>3
    4:移動3:1=>2
    5:移動1:3=>1
    6:移動2:3=>2
    7:移動1:1=>2
    8:移動4:1=>3
    9:移動1:2=>3
    10:移動2:2=>1
    11:移動1:3=>1
    12:移動3:2=>3
    13:移動1:1=>2
    14:移動2:1=>3
    15:移動1:2=>3

    2016年12月26日 下午12:10
    匿名 B10233049 黃家崙 提到...
    package hello;
    public class hello{
    static int N=0;
    static void hanoi(int A,int B, int C, int n){
    if (n==1)
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    else
    {
    hanoi(A , C, B, n-1);
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    hanoi(B , A, C, n-1);
    }
    }

    public static void main (String[] args){
    hanoi (1,2,3, 4);
    }
    }

    ------------------------------------
    1:移動1:1=>2
    2:移動2:1=>3
    3:移動1:2=>3
    4:移動3:1=>2
    5:移動1:3=>1
    6:移動2:3=>2
    7:移動1:1=>2
    8:移動4:1=>3
    9:移動1:2=>3
    10:移動2:2=>1
    11:移動1:3=>1
    12:移動3:2=>3
    13:移動1:1=>2
    14:移動2:1=>3
    15:移動1:2=>3

    回覆刪除
  50. package hello;
    public class hello{
    static int N=0;
    static void hanoi(int A,int B, int C, int n){
    if (n==1)
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    else
    {
    hanoi(A , C, B, n-1);
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    hanoi(B , A, C, n-1);
    }
    }

    public static void main (String[] args){
    hanoi (1,2,3, 4);
    }
    }

    ------------------------------------
    1:移動1:1=>2
    2:移動2:1=>3
    3:移動1:2=>3
    4:移動3:1=>2
    5:移動1:3=>1
    6:移動2:3=>2
    7:移動1:1=>2
    8:移動4:1=>3
    9:移動1:2=>3
    10:移動2:2=>1
    11:移動1:3=>1
    12:移動3:2=>3
    13:移動1:1=>2
    14:移動2:1=>3
    15:移動1:2=>3

    2016年12月26日 下午12:10
    匿名 B10233049 黃家崙 提到...
    package hello;
    public class hello{
    static int N=0;
    static void hanoi(int A,int B, int C, int n){
    if (n==1)
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    else
    {
    hanoi(A , C, B, n-1);
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    hanoi(B , A, C, n-1);
    }
    }

    public static void main (String[] args){
    hanoi (1,2,3, 4);
    }
    }

    ------------------------------------
    1:移動1:1=>2
    2:移動2:1=>3
    3:移動1:2=>3
    4:移動3:1=>2
    5:移動1:3=>1
    6:移動2:3=>2
    7:移動1:1=>2
    8:移動4:1=>3
    9:移動1:2=>3
    10:移動2:2=>1
    11:移動1:3=>1
    12:移動3:2=>3
    13:移動1:1=>2
    14:移動2:1=>3
    15:移動1:2=>3

    回覆刪除

  51. package hello;
    public class hello{
    static int N=0;
    static void hanoi(int A,int B, int C, int n){
    if (n==1)
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    else
    {
    hanoi(A , C, B, n-1);
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    hanoi(B , A, C, n-1);
    }
    }

    public static void main (String[] args){
    hanoi (1,2,3, 4);
    }
    }

    ------------------------------------
    1:移動1:1=>2
    2:移動2:1=>3
    3:移動1:2=>3
    4:移動3:1=>2
    5:移動1:3=>1
    6:移動2:3=>2
    7:移動1:1=>2
    8:移動4:1=>3
    9:移動1:2=>3
    10:移動2:2=>1
    11:移動1:3=>1
    12:移動3:2=>3
    13:移動1:1=>2
    14:移動2:1=>3
    15:移動1:2=>3

    回覆刪除
  52. b10233028 王曉琪2016年12月28日 晚上8:30

    package hello;
    public class hello{
    static int N=0;
    static void hanoi(int A,int B, int C, int n){
    if (n==1)
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    else
    {
    hanoi(A , C, B, n-1);
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    hanoi(B , A, C, n-1);
    }
    }

    public static void main (String[] args){
    hanoi (1,2,3, 4);
    }
    }

    ------------------------------------
    1:移動1:1=>2
    2:移動2:1=>3
    3:移動1:2=>3
    4:移動3:1=>2
    5:移動1:3=>1
    6:移動2:3=>2
    7:移動1:1=>2
    8:移動4:1=>3
    9:移動1:2=>3
    10:移動2:2=>1
    11:移動1:3=>1
    12:移動3:2=>3
    13:移動1:1=>2
    14:移動2:1=>3
    15:移動1:2=>3

    回覆刪除
  53. package hello;
    public class hello{
    static int N=0;
    static void hanoi(int A,int B, int C, int n){
    if (n==1)
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    else
    {
    hanoi(A , C, B, n-1);
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    hanoi(B , A, C, n-1);
    }
    }

    public static void main (String[] args){
    hanoi (1,2,3, 4);
    }
    }

    ------------------------------------
    1:移動1:1=>2
    2:移動2:1=>3
    3:移動1:2=>3
    4:移動3:1=>2
    5:移動1:3=>1
    6:移動2:3=>2
    7:移動1:1=>2
    8:移動4:1=>3
    9:移動1:2=>3
    10:移動2:2=>1
    11:移動1:3=>1
    12:移動3:2=>3
    13:移動1:1=>2
    14:移動2:1=>3
    15:移動1:2=>3

    回覆刪除
  54. public class ex01 {
    static int N=0;
    static void hanoi (char A, char B, char C, int n){
    if (n==1)
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    else{
    hanoi(A,C,B, n-1);
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    hanoi(B,A,C, n-1);
    }
    }

    public static void main(String[] args) {
    hanoi('A','B','C', 5);

    }
    }

    回覆刪除
  55. public class ex01 {
    static int N=0;
    static void hanoi (char A, char B, char C, int n){
    if (n==1)
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    else{
    hanoi(A,C,B, n-1);
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    hanoi(B,A,C, n-1);
    }
    }

    public static void main(String[] args) {
    hanoi('A','B','C', 5);

    }
    }

    回覆刪除
  56. package hello;
    public class hello{
    static int N=0;
    static void hanoi(int A,int B, int C, int n){
    if (n==1)
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    else
    {
    hanoi(A , C, B, n-1);
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    hanoi(B , A, C, n-1);
    }
    }

    public static void main (String[] args){
    hanoi (1,2,3, 4);
    }
    }

    ------------------------------------
    1:移動1:1=>2
    2:移動2:1=>3
    3:移動1:2=>3
    4:移動3:1=>2
    5:移動1:3=>1
    6:移動2:3=>2
    7:移動1:1=>2
    8:移動4:1=>3
    9:移動1:2=>3
    10:移動2:2=>1
    11:移動1:3=>1
    12:移動3:2=>3
    13:移動1:1=>2
    14:移動2:1=>3
    15:移動1:2=>3

    回覆刪除
  57. B10433035 劉軒宇2017年1月1日 晚上10:42

    package hello;
    public class hello{
    static int N=0;
    static void hanoi(int A,int B, int C, int n){
    if (n==1)
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    else
    {
    hanoi(A , C, B, n-1);
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    hanoi(B , A, C, n-1);
    }
    }

    public static void main (String[] args){
    hanoi (1,2,3, 4);
    }
    }

    ------------------------------------
    1:移動1:1=>2
    2:移動2:1=>3
    3:移動1:2=>3
    4:移動3:1=>2
    5:移動1:3=>1
    6:移動2:3=>2
    7:移動1:1=>2
    8:移動4:1=>3
    9:移動1:2=>3
    10:移動2:2=>1
    11:移動1:3=>1
    12:移動3:2=>3
    13:移動1:1=>2
    14:移動2:1=>3
    15:移動1:2=>3

    回覆刪除
  58. b10433012 鍾仁凱2017年1月2日 下午3:24

    package hello;

    public class ex01 {
    static int N=0;
    static void hanoi(char A,char B,char C,int n){
    if(n==1)
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    else{
    hanoi(A,B,C,n-1);
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    hanoi(A,B,C,n-1);
    }
    }

    public static void main(String[] args) {
    hanoi('A','B','C',5);

    }

    }

    回覆刪除
  59. B10233187 張郁柔2017年1月4日 上午9:21

    package hello;
    public class hello{
    static int N=0;
    static void hanoi(int A,int B, int C, int n){
    if (n==1)
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    else
    {
    hanoi(A , C, B, n-1);
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    hanoi(B , A, C, n-1);
    }
    }

    public static void main (String[] args){
    hanoi (1,2,3, 4);
    }
    }

    ------------------------------------
    1:移動1:1=>2
    2:移動2:1=>3
    3:移動1:2=>3
    4:移動3:1=>2
    5:移動1:3=>1
    6:移動2:3=>2
    7:移動1:1=>2
    8:移動4:1=>3
    9:移動1:2=>3
    10:移動2:2=>1
    11:移動1:3=>1
    12:移動3:2=>3
    13:移動1:1=>2
    14:移動2:1=>3
    15:移動1:2=>3

    回覆刪除
  60. B10233136 巫駿驛2017年1月4日 上午10:16

    package hello;
    public class hello{
    static int N=0;
    static void hanoi(int A,int B, int C, int n){
    if (n==1)
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    else
    {
    hanoi(A , C, B, n-1);
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    hanoi(B , A, C, n-1);
    }
    }

    public static void main (String[] args){
    hanoi (1,2,3, 4);
    }
    }

    ------------------------------------
    1:移動1:1=>2
    2:移動2:1=>3
    3:移動1:2=>3
    4:移動3:1=>2
    5:移動1:3=>1
    6:移動2:3=>2
    7:移動1:1=>2
    8:移動4:1=>3
    9:移動1:2=>3
    10:移動2:2=>1
    11:移動1:3=>1
    12:移動3:2=>3
    13:移動1:1=>2
    14:移動2:1=>3
    15:移動1:2=>3

    回覆刪除
  61. b10433043彭子豪2017年1月4日 上午10:42

    package hello;
    public class hello{
    static int N=0;
    static void hanoi(int A,int B, int C, int n){
    if (n==1)
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    else
    {
    hanoi(A , C, B, n-1);
    System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
    hanoi(B , A, C, n-1);
    }
    }

    public static void main (String[] args){
    hanoi (1,2,3, 4);
    }
    }

    ------
    1:移動1:1=>2
    2:移動2:1=>3
    3:移動1:2=>3
    4:移動3:1=>2
    5:移動1:3=>1
    6:移動2:3=>2
    7:移動1:1=>2
    8:移動4:1=>3
    9:移動1:2=>3
    10:移動2:2=>1
    11:移動1:3=>1
    12:移動3:2=>3
    13:移動1:1=>2
    14:移動2:1=>3
    15:移動1:2=>3

    回覆刪除

HTML 編輯器