Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Main {
- public static void main(String[] args) {
- int numOfDiscs = 8;
- solveHanoiTower(numOfDiscs, 'A', 'C', 'B');
- }
- public static void solveHanoiTower(int n, char source, char destination, char auxiliary){
- if (n == 1) {
- System.out.println("Переместить диск 1 из " + source + " в " + destination);
- return;
- }
- solveHanoiTower(n - 1, source, auxiliary, destination);
- System.out.println("Переместить диск " + n + " из " + source + " в " + destination);
- solveHanoiTower(n - 1, auxiliary, destination, source);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement