Advertisement
bobo_bobkata

Untitled

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