Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Towers {
- private static void towerOfHanoi(int count, char fromRod, char toRod, char auxRod) {
- if (count == 1) {
- System.out.println(String.format("Disk nomer 1 ot konus %c kum konus %c", fromRod, toRod));
- return;
- }
- towerOfHanoi(count - 1, fromRod, auxRod, toRod);
- System.out.println(String.format("Disk nomer %d ot konus %c kum konus %c", count, fromRod, toRod));
- towerOfHanoi(count - 1, auxRod, toRod, fromRod);
- }
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int count = Integer.parseInt(scanner.nextLine());
- towerOfHanoi(count, 'A', 'C', 'B');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement