Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package pertemuan4;
- import java.util.Scanner;
- public class nomor2 {
- static int move = 1;
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- System.out.println("PROGRAM TOWERS OF HANOI ");
- System.out.println("========================");
- System.out.println("\nMasukan Jumlah piringan: ");
- int Cakram = input.nextInt();
- hanoi (Cakram, 'A', 'B', 'C');}
- static void hanoi (int Cakram, char awal, char bantu, char tujuan){
- if (Cakram >= 1) {
- hanoi (Cakram-1, awal, tujuan, bantu);
- move(Cakram, awal, tujuan);
- hanoi (Cakram-1, bantu, awal, tujuan);
- }
- }
- static void move (int step, char awal, char tujuan){
- System.out.println("Langkah "+move);
- move++;
- System.out.print("Pindahkan Cakram "+step);
- System.out.print(" dari "+awal);
- System.out.println(" ke "+tujuan);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement