Advertisement
Telor_Goreng0

nomor 2 pertemuan 4

Apr 24th, 2021
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. package pertemuan4;
  2. import java.util.Scanner;
  3.  
  4. public class nomor2 {
  5. static int move = 1;
  6. public static void main(String[] args) {
  7. Scanner input = new Scanner(System.in);
  8. System.out.println("PROGRAM TOWERS OF HANOI ");
  9. System.out.println("========================");
  10. System.out.println("\nMasukan Jumlah piringan: ");
  11. int Cakram = input.nextInt();
  12. hanoi (Cakram, 'A', 'B', 'C');}
  13. static void hanoi (int Cakram, char awal, char bantu, char tujuan){
  14. if (Cakram >= 1) {
  15. hanoi (Cakram-1, awal, tujuan, bantu);
  16. move(Cakram, awal, tujuan);
  17. hanoi (Cakram-1, bantu, awal, tujuan);
  18. }
  19. }
  20. static void move (int step, char awal, char tujuan){
  21. System.out.println("Langkah "+move);
  22. move++;
  23. System.out.print("Pindahkan Cakram "+step);
  24. System.out.print(" dari "+awal);
  25. System.out.println(" ke "+tujuan);
  26. }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement