網頁

2013年12月9日 星期一

河內塔java程式



35 則留言:

  1. B10133048 饒家華2013年12月10日 上午8:23

    public class HanoiTower {
    static int count=0;
    static void h(int d, int peg1, int peg2, int peg3){
    if (d==1)
    System.out.println((++count)+"次:盤子"+"◎"+"從"+peg1+"move"+"→"+peg3);
    else{
    h(d-1,peg1,peg3,peg2);
    System.out.println((++count)+"次:盤子"+"◎"+"從"+peg1+"move"+"→"+peg3);
    h(d-1,peg2,peg1,peg3);
    }
    }
    public static void main(String[] args) {
    int d=3;
    h(d,1,2,3);

    }

    }

    回覆刪除
  2. B10133048 饒家華2013年12月10日 上午8:34

    public class HanoiTower {
    static int count=0;
    static void h(int d, int peg1, int peg2, int peg3){
    if (d==1)
    System.out.println((++count)+"次:盤子"+"◎"+d+"從"+peg1+"move"+"→"+peg3);

    else{
    h(d-1,peg1,peg3,peg2);
    System.out.println((++count)+"次:盤子"+"◎"+d+"從"+peg1+"move"+"→"+peg3);
    h(d-1,peg2,peg1,peg3);
    }
    }
    public static void main(String[] args) {
    int d=3;
    h(d,1,2,3);

    }

    }

    回覆刪除
  3. public class HanoiTower {
    static int count=0;
    static void h(int d, int peg1, int peg2, int peg3){
    if (d==1)
    System.out.println((++count)+"次:盤子"+"◎"+d+"從"+peg1+"move"+"→"+peg3);

    else{
    h(d-1,peg1,peg3,peg2);
    System.out.println((++count)+"次:盤子"+"◎"+d+"從"+peg1+"move"+"→"+peg3);
    h(d-1,peg2,peg1,peg3);
    }
    }
    public static void main(String[] args) {
    int d=3;
    h(d,1,2,3);

    }

    }

    回覆刪除
  4. public class HanoiTower {
    static int count=0;
    static void h(int d, int peg1, int peg2, int peg3){
    if (d==1)
    System.out.println((++count)+"次:盤子"+"◎"+"從"+peg1+"move"+"→"+peg3);
    else{
    h(d-1,peg1,peg3,peg2);
    System.out.println((++count)+"次:盤子"+"◎"+"從"+peg1+"move"+"→"+peg3);
    h(d-1,peg2,peg1,peg3);
    }
    }
    public static void main(String[] args) {
    int d=3;
    h(d,1,2,3);

    }

    }

    回覆刪除
  5. B10133025 王柏文
    public class HanoiTower {
    static int count=0;
    static void h(int d, int peg1, int peg2, int peg3){
    if (d==1)
    System.out.println((++count)+"次:盤子"+"◎"+"從"+peg1+"move"+"→"+peg3);
    else{
    h(d-1,peg1,peg3,peg2);
    System.out.println((++count)+"次:盤子"+"◎"+"從"+peg1+"move"+"→"+peg3);
    h(d-1,peg2,peg1,peg3);
    }
    }
    public static void main(String[] args) {
    int d=3;
    h(d,1,2,3);

    }

    }

    回覆刪除
  6. public class HanoiTower {
    static int count=0;
    static void h(int d, int peg1, int peg2, int peg3){
    if (d==1)
    System.out.println((++count)+"次:盤子"+"◎"+d+"從"+peg1+"move"+"→"+peg3);

    else{
    h(d-1,peg1,peg3,peg2);
    System.out.println((++count)+"次:盤子"+"◎"+d+"從"+peg1+"move"+"→"+peg3);
    h(d-1,peg2,peg1,peg3);
    }
    }
    public static void main(String[] args) {
    int d=3;
    h(d,1,2,3);

    }

    }

    回覆刪除
  7. public class HanoiTower {
    static int count=0;
    static void h(int d, int peg1, int peg2, int peg3){
    if (d==1)
    System.out.println((++count)+"次:盤子"+"◎"+"從"+peg1+"move"+"→"+peg3);
    else{
    h(d-1,peg1,peg3,peg2);
    System.out.println((++count)+"次:盤子"+"◎"+"從"+peg1+"move"+"→"+peg3);
    h(d-1,peg2,peg1,peg3);
    }
    }
    public static void main(String[] args) {
    int d=3;
    h(d,1,2,3);

    }

    }

    回覆刪除
  8. public class sam {
    static int count=0;
    static void h(int d, int peg1, int peg2, int peg3){
    if (d==1)
    System.out.println((++count)+"次:盤子"+"◎"+"從"+peg1+"move"+"→"+peg3);
    else{
    h(d-1,peg1,peg3,peg2);
    System.out.println((++count)+"次:盤子"+"◎"+"從"+peg1+"move"+"→"+peg3);
    h(d-1,peg2,peg1,peg3);
    }
    }
    public static void main(String[] args) {
    int d=3;
    h(d,1,2,3);

    }

    }

    回覆刪除
  9. public class ds {
    static int count=0;
    static void h(int d, int peg1, int peg2, int peg3){
    if (d==1)
    System.out.println((++count)+"次:盤子"+"◎"+"從"+peg1+"move"+"→"+peg3);
    else{
    h(d-1,peg1,peg3,peg2);
    System.out.println((++count)+"次:盤子"+"◎"+"從"+peg1+"move"+"→"+peg3);
    h(d-1,peg2,peg1,peg3);
    }
    }
    public static void main(String[] args) {
    int d=3;
    h(d,1,2,3);

    }

    }

    回覆刪除
  10. public class adsl {
    static int count=0;
    static void h(int d, int peg1, int peg2, int peg3){
    if (d==1)
    System.out.println((++count)+"次:盤子"+"◎"+"從"+peg1+"move"+"→"+peg3);
    else{
    h(d-1,peg1,peg3,peg2);
    System.out.println((++count)+"次:盤子"+"◎"+"從"+peg1+"move"+"→"+peg3);
    h(d-1,peg2,peg1,peg3);
    }
    }
    public static void main(String[] args) {
    int d=3;
    h(d,1,2,3);

    }

    }

    回覆刪除
  11. public class sup {
    static int count=0;
    static void h(int d, int peg1, int peg2, int peg3){
    if (d==1)
    System.out.println((++count)+"次:盤子"+"◎"+"從"+peg1+"move"+"→"+peg3);
    else{
    h(d-1,peg1,peg3,peg2);
    System.out.println((++count)+"次:盤子"+"◎"+"從"+peg1+"move"+"→"+peg3);
    h(d-1,peg2,peg1,peg3);
    }
    }
    public static void main(String[] args) {
    int d=3;
    h(d,1,2,3);

    }

    }

    回覆刪除
  12. public class AD {
    static int count=0;
    static void h(int d, int peg1, int peg2, int peg3){
    if (d==1)
    System.out.println((++count)+"次:盤子"+"◎"+"從"+peg1+"move"+"→"+peg3);
    else{
    h(d-1,peg1,peg3,peg2);
    System.out.println((++count)+"次:盤子"+"◎"+"從"+peg1+"move"+"→"+peg3);
    h(d-1,peg2,peg1,peg3);
    }
    }
    public static void main(String[] args) {
    int d=3;
    h(d,1,2,3);

    }

    }

    回覆刪除
  13. public class jpm {
    static int count=0;
    static void h(int d, int peg1, int peg2, int peg3){
    if (d==1)
    System.out.println((++count)+"次:盤子"+"◎"+"從"+peg1+"move"+"→"+peg3);
    else{
    h(d-1,peg1,peg3,peg2);
    System.out.println((++count)+"次:盤子"+"◎"+"從"+peg1+"move"+"→"+peg3);
    h(d-1,peg2,peg1,peg3);
    }
    }
    public static void main(String[] args) {
    int d=3;
    h(d,1,2,3);

    }

    }

    回覆刪除
  14. public class AK {
    static int count=0;
    static void h(int d, int peg1, int peg2, int peg3){
    if (d==1)
    System.out.println((++count)+"次:盤子"+"◎"+"從"+peg1+"move"+"→"+peg3);
    else{
    h(d-1,peg1,peg3,peg2);
    System.out.println((++count)+"次:盤子"+"◎"+"從"+peg1+"move"+"→"+peg3);
    h(d-1,peg2,peg1,peg3);
    }
    }
    public static void main(String[] args) {
    int d=3;
    h(d,1,2,3);

    }

    }

    回覆刪除
  15. public class HanoiTower {
    static int count=0;
    static void h(int d, int peg1, int peg2, int peg3){
    if (d==1)
    System.out.println((++count)+"次:盤子"+"◎"+d+"從"+peg1+"move"+"→"+peg3);

    else{
    h(d-1,peg1,peg3,peg2);
    System.out.println((++count)+"次:盤子"+"◎"+d+"從"+peg1+"move"+"→"+peg3);
    h(d-1,peg2,peg1,peg3);
    }
    }
    public static void main(String[] args) {
    int d=3;
    h(d,1,2,3);

    }

    }

    回覆刪除
  16. public class HanoiTower {
    static int count=0;
    static void h(int d, int peg1, int peg2, int peg3){
    if (d==1)
    System.out.println((++count)+"次:盤子"+"◎"+d+"從"+peg1+"move"+"→"+peg3);

    else{
    h(d-1,peg1,peg3,peg2);
    System.out.println((++count)+"次:盤子"+"◎"+d+"從"+peg1+"move"+"→"+peg3);
    h(d-1,peg2,peg1,peg3);
    }
    }
    public static void main(String[] args) {
    int d=3;
    h(d,1,2,3);

    }

    }

    回覆刪除
  17. public class HanoiTower {
    static int count=0;
    static void h(int d, int peg1, int peg2, int peg3){
    if (d==1)
    System.out.println((++count)+"次:盤子"+"◎"+d+"從"+peg1+"move"+"→"+peg3);

    else{
    h(d-1,peg1,peg3,peg2);
    System.out.println((++count)+"次:盤子"+"◎"+d+"從"+peg1+"move"+"→"+peg3);
    h(d-1,peg2,peg1,peg3);
    }
    }
    public static void main(String[] args) {
    int d=3;
    h(d,1,2,3);

    }

    }

    回覆刪除
  18. public class HanoiTower {
    static int count=0;
    static void h(int d, int peg1, int peg2, int peg3){
    if (d==1)
    System.out.println((++count)+"次:盤子"+"◎"+d+"從"+peg1+"move"+"→"+peg3);

    else{
    h(d-1,peg1,peg3,peg2);
    System.out.println((++count)+"次:盤子"+"◎"+d+"從"+peg1+"move"+"→"+peg3);
    h(d-1,peg2,peg1,peg3);
    }
    }
    public static void main(String[] args) {
    int d=3;
    h(d,1,2,3);

    }

    }

    回覆刪除
  19. public class ket {
    static int count=0;
    static void h(int d, int peg1, int peg2, int peg3){
    if (d==1)
    System.out.println((++count)+"次:盤子"+"◎"+d+"從"+peg1+"move"+"→"+peg3);

    else{
    h(d-1,peg1,peg3,peg2);
    System.out.println((++count)+"次:盤子"+"◎"+d+"從"+peg1+"move"+"→"+peg3);
    h(d-1,peg2,peg1,peg3);
    }
    }
    public static void main(String[] args) {
    int d=3;
    h(d,1,2,3);

    }

    }

    回覆刪除
  20. public class wen {
    static int count=0;
    static void h(int d, int peg1, int peg2, int peg3){
    if (d==1)
    System.out.println((++count)+"次:盤子"+"◎"+d+"從"+peg1+"move"+"→"+peg3);

    else{
    h(d-1,peg1,peg3,peg2);
    System.out.println((++count)+"次:盤子"+"◎"+d+"從"+peg1+"move"+"→"+peg3);
    h(d-1,peg2,peg1,peg3);
    }
    }
    public static void main(String[] args) {
    int d=3;
    h(d,1,2,3);

    }

    }

    回覆刪除
  21. public class sup {
    static int count=0;
    static void h(int d, int peg1, int peg2, int peg3){
    if (d==1)
    System.out.println((++count)+"次:盤子"+"◎"+"從"+peg1+"move"+"→"+peg3);
    else{
    h(d-1,peg1,peg3,peg2);
    System.out.println((++count)+"次:盤子"+"◎"+"從"+peg1+"move"+"→"+peg3);
    h(d-1,peg2,peg1,peg3);
    }
    }
    public static void main(String[] args) {
    int d=3;
    h(d,1,2,3);

    }

    }

    回覆刪除
  22. public class HanoiTower {
    static int count=0;
    static void h(int d, int peg1, int peg2, int peg3){
    if (d==1)
    System.out.println((++count)+"次:盤子"+"◎"+d+"從"+peg1+"move"+"→"+peg3);

    else{
    h(d-1,peg1,peg3,peg2);
    System.out.println((++count)+"次:盤子"+"◎"+d+"從"+peg1+"move"+"→"+peg3);
    h(d-1,peg2,peg1,peg3);
    }
    }
    public static void main(String[] args) {
    int d=3;
    h(d,1,2,3);

    }

    }

    回覆刪除
  23. public class HanoiTower {
    static int count=0;
    static void h(int d, int peg1, int peg2, int peg3){
    if (d==1)
    System.out.println((++count)+"次:盤子"+"◎"+d+"從"+peg1+"move"+"→"+peg3);

    else{
    h(d-1,peg1,peg3,peg2);
    System.out.println((++count)+"次:盤子"+"◎"+d+"從"+peg1+"move"+"→"+peg3);
    h(d-1,peg2,peg1,peg3);
    }
    }
    public static void main(String[] args) {
    int d=3;
    h(d,1,2,3);

    }

    }

    回覆刪除
  24. public class HanoiTower {
    static int count=0;
    static void h(int d, int peg1, int peg2, int peg3){
    if (d==1)
    System.out.println((++count)+"次:盤子"+"◎"+"從"+peg1+"move"+"→"+peg3);
    else{
    h(d-1,peg1,peg3,peg2);
    System.out.println((++count)+"次:盤子"+"◎"+"從"+peg1+"move"+"→"+peg3);
    h(d-1,peg2,peg1,peg3);
    }
    }
    public static void main(String[] args) {
    int d=3;
    h(d,1,2,3);

    }

    }

    回覆刪除
  25. public class HanoiTower {
    static int count=0;
    static void h(int d, int peg1, int peg2, int peg3){
    if (d==1)
    System.out.println((++count)+"次:盤子"+"◎"+"從"+peg1+"move"+"→"+peg3);
    else{
    h(d-1,peg1,peg3,peg2);
    System.out.println((++count)+"次:盤子"+"◎"+"從"+peg1+"move"+"→"+peg3);
    h(d-1,peg2,peg1,peg3);
    }
    }
    public static void main(String[] args) {
    int d=3;
    h(d,1,2,3);

    }

    }

    回覆刪除
  26. public class HanoiTower {
    static int count=0;
    static void h(int d, int peg1, int peg2, int peg3){
    if (d==1)
    System.out.println((++count)+"次:盤子"+"◎"+"從"+peg1+"move"+"→"+peg3);
    else{
    h(d-1,peg1,peg3,peg2);
    System.out.println((++count)+"次:盤子"+"◎"+"從"+peg1+"move"+"→"+peg3);
    h(d-1,peg2,peg1,peg3);
    }
    }
    public static void main(String[] args) {
    int d=3;
    h(d,1,2,3);

    }

    }

    回覆刪除
  27. public class HanoiTower {
    static int count=0;
    static void h(int d, int peg1, int peg2, int peg3){
    if (d==1)
    System.out.println((++count)+"次:盤子"+"◎"+"從"+peg1+"move"+"→"+peg3);
    else{
    h(d-1,peg1,peg3,peg2);
    System.out.println((++count)+"次:盤子"+"◎"+"從"+peg1+"move"+"→"+peg3);
    h(d-1,peg2,peg1,peg3);
    }
    }
    public static void main(String[] args) {
    int d=3;
    h(d,1,2,3);

    }

    }

    回覆刪除
  28. public class HanoiTower {
    static int count=0;
    static void h(int d, int peg1, int peg2, int peg3){
    if (d==1)
    System.out.println((++count)+"次:盤子"+"◎"+"從"+peg1+"move"+"→"+peg3);
    else{
    h(d-1,peg1,peg3,peg2);
    System.out.println((++count)+"次:盤子"+"◎"+"從"+peg1+"move"+"→"+peg3);
    h(d-1,peg2,peg1,peg3);
    }
    }
    public static void main(String[] args) {
    int d=3;
    h(d,1,2,3);

    }

    }

    回覆刪除
  29. public class HanoiTower {
    static int count=0;
    static void h(int d, int peg1, int peg2, int peg3){
    if (d==1)
    System.out.println((++count)+"次:盤子"+"◎"+"從"+peg1+"move"+"→"+peg3);
    else{
    h(d-1,peg1,peg3,peg2);
    System.out.println((++count)+"次:盤子"+"◎"+"從"+peg1+"move"+"→"+peg3);
    h(d-1,peg2,peg1,peg3);
    }
    }
    public static void main(String[] args) {
    int d=3;
    h(d,1,2,3);

    }

    }

    回覆刪除
  30. public class HanoiTower {
    static int count=0;
    static void h(int d, int peg1, int peg2, int peg3){
    if (d==1)
    System.out.println((++count)+"次:盤子"+"◎"+"從"+peg1+"move"+"→"+peg3);
    else{
    h(d-1,peg1,peg3,peg2);
    System.out.println((++count)+"次:盤子"+"◎"+"從"+peg1+"move"+"→"+peg3);
    h(d-1,peg2,peg1,peg3);
    }
    }
    public static void main(String[] args) {
    int d=3;
    h(d,1,2,3);

    }

    }

    回覆刪除
  31. public class HanoiTower {
    static int count=0;
    static void h(int d, int peg1, int peg2, int peg3){
    if (d==1)
    System.out.println((++count)+"次:盤子"+"◎"+d+"從"+peg1+"move"+"→"+peg3);

    else{
    h(d-1,peg1,peg3,peg2);
    System.out.println((++count)+"次:盤子"+"◎"+d+"從"+peg1+"move"+"→"+peg3);
    h(d-1,peg2,peg1,peg3);
    }
    }
    public static void main(String[] args) {
    int d=3;
    h(d,1,2,3);

    }

    }

    回覆刪除
  32. public class HanoiTower {
    static int count=0;
    static void h(int d, int peg1, int peg2, int peg3){
    if (d==1)
    System.out.println((++count)+"次:盤子"+"◎"+"從"+peg1+"move"+"→"+peg3);
    else{
    h(d-1,peg1,peg3,peg2);
    System.out.println((++count)+"次:盤子"+"◎"+"從"+peg1+"move"+"→"+peg3);
    h(d-1,peg2,peg1,peg3);
    }
    }
    public static void main(String[] args) {
    int d=3;
    h(d,1,2,3);

    }

    }

    回覆刪除
  33. public class HanoiTower {
    static int count=0;
    static void h(int d, int peg1, int peg2, int peg3){
    if (d==1)
    System.out.println((++count)+"次:盤子"+"◎"+"從"+peg1+"move"+"→"+peg3);
    else{
    h(d-1,peg1,peg3,peg2);
    System.out.println((++count)+"次:盤子"+"◎"+"從"+peg1+"move"+"→"+peg3);
    h(d-1,peg2,peg1,peg3);
    }
    }
    public static void main(String[] args) {
    int d=3;
    h(d,1,2,3);

    }

    }

    回覆刪除
  34. B10133020 李涵清2013年12月29日 晚上9:06

    public class HanoiTower {
    static int count=0;
    static void h(int d, int peg1, int peg2, int peg3){
    if (d==1)
    System.out.println((++count)+"次:盤子"+"◎"+"從"+peg1+"move"+"→"+peg3);
    else{
    h(d-1,peg1,peg3,peg2);
    System.out.println((++count)+"次:盤子"+"◎"+"從"+peg1+"move"+"→"+peg3);
    h(d-1,peg2,peg1,peg3);
    }
    }
    public static void main(String[] args) {
    int d=3;
    h(d,1,2,3);

    }

    }

    回覆刪除
  35. public class HanoiTower {
    static int count=0;
    static void h(int d, int peg1, int peg2, int peg3){
    if (d==1)
    System.out.println((++count)+"次:盤子"+"◎"+"從"+peg1+"move"+"→"+peg3);
    else{
    h(d-1,peg1,peg3,peg2);
    System.out.println((++count)+"次:盤子"+"◎"+"從"+peg1+"move"+"→"+peg3);
    h(d-1,peg2,peg1,peg3);
    }
    }
    public static void main(String[] args) {
    int d=3;
    h(d,1,2,3);

    }

    }

    回覆刪除

HTML 編輯器