FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
code-backup/5th_sem_C_Java_VB/Java/tower.java at master · Jimut123/code-backup · GitHub
This repository was archived by the owner on Jul 28, 2024. It is now read-only.
Jimut123
/
code-backup
Public archive
Notifications
You must be signed in to change notification settings
Fork
6
Star
20
Code
Issues
0
Pull requests
35
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
code-backup
/
5th_sem_C_Java_VB
/
Java
/
tower.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
105 lines (36 loc) · 1.04 KB
Breadcrumbs
code-backup
/
5th_sem_C_Java_VB
/
Java
/
tower.java
Copy path
File metadata and controls
105 lines (36 loc) · 1.04 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import
java
.
io
.*;
class
Hanoi
{
int
n
;
Hanoi
(
int
m
)
{
n
=
m
;
}
void
hanoi
(
int
p1
,
int
p2
,
int
p3
,
int
nd
)
{
if
(
nd
==
1
)
{
n
=
n
+
1
;
System
.
out
.
println
(
"Step-"
+
n
+
" :"
+
" Move Disk-"
+
nd
+
" From Peg-"
+
p1
+
" to Peg-"
+
p2
);
return
;
}
hanoi
(
p1
,
p3
,
p2
,
nd
-
1
);
n
=
n
+
1
;
System
.
out
.
println
(
"Step-"
+
n
+
" :"
+
" Move Disk-"
+
nd
+
" From Peg-"
+
p1
+
" to Peg-"
+
p2
);
hanoi
(
p3
,
p2
,
p1
,
nd
-
1
);
}
}
class
tower
{
public
static
void
main
(
String
args
[])
throws
IOException
{
int
p1
=
1
,
p2
=
2
,
p3
=
3
,
nd
,
n
;
BufferedReader
br
=
new
BufferedReader
(
new
InputStreamReader
(
System
.
in
));
System
.
out
.
print
(
"
\n
Enter Number of Disks(1-5)="
);
nd
=
Integer
.
parseInt
(
br
.
readLine
());
n
=
0
;
Hanoi
H
=
new
Hanoi
(
n
);
H
.
hanoi
(
p1
,
p2
,
p3
,
nd
);
System
.
out
.
println
(
"Total number of iterations : "
+
H
.
n
);
}
}
Back
|
FazBrowse Home
|
New Git URL