herrDeng網內搜尋
自訂搜尋
Ads
訂閱:
張貼留言 (Atom)
熱門文章
-
請用Random產生20個0~99的奇數(可重複),然後排序
-
連續複利
-
C++ Py3 計數排序與partial sum解Leetcode 2300 Successful Pairs of Spells and Potions Portions的極大值小於等於10萬是可進行記數排序的關鍵,既然可以採用記數排序,後面的二元搜尋也可以透過part...
-
輸入公元n年,輸出"平年" "閏年"
-
Py3 C++ C 2pointer速解Leetcode 11Container With Most Water [Py3 code請進]
-
Py3 C++計數bitmask與2 pointers速解Leetcode2273 Find Resultant Array After Removing Anagrams 字串長度最長也只有10,四個bits一組,用bitmask解題 ----- The maximum le...
61 則留言:
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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
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
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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
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
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
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
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
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);
}
}
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
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
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);
}
}
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);
}
}
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);
}
}
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
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
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
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
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);
}
}
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);
}
}
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
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
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
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
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);
}
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
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
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
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
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
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
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
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);
}
}
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);
}
}
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
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
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);
}
}
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
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
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
張貼留言