Advertisement
bobo_bobkata

Untitled

Nov 14th, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Towers {
  4.  
  5. private static void towerOfHanoi(int count, char fromRod, char toRod, char auxRod) {
  6. if (count == 1) {
  7. System.out.println(String.format("Disk nomer 1 ot konus %c kum konus %c", fromRod, toRod));
  8. return;
  9. }
  10. towerOfHanoi(count - 1, fromRod, auxRod, toRod);
  11. System.out.println(String.format("Disk nomer %d ot konus %c kum konus %c", count, fromRod, toRod));
  12. towerOfHanoi(count - 1, auxRod, toRod, fromRod);
  13. }
  14.  
  15. public static void main(String[] args) {
  16. Scanner scanner = new Scanner(System.in);
  17. int count = Integer.parseInt(scanner.nextLine());
  18. towerOfHanoi(count, 'A', 'C', 'B');
  19. }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement