tower of hanoi program in java using recursion
Java
// Java recursive program to solve tower of hanoi puzzle
class GFG
{
// Java recursive function to solve tower of hanoi puzzle
static void towerOfHanoi(int n, char from_rod, char to_rod, char aux_rod)
{
if (n == 1)
{
System.out.println("Move disk 1 from rod " + from_rod + " to rod " + to_rod);
return;
}
towerOfHanoi(n-1, from_rod, aux_rod, to_rod);
System.out.println("Move disk " + n + " from rod " + from_rod + " to rod " + to_rod);
towerOfHanoi(n-1, aux_rod, to_rod, from_rod);
}
// Driver method
public static void main(String args[])
{
int n = 4; // Number of disks
towerOfHanoi(n, 'A', 'C', 'B'); // A, B and C are names of rods
}
}
Also in Java:
- Title
- cgange background from button click java fx
- Category
- Java
- Title
- java how to make a gui
- Category
- Java
- Title
- onbackpressed android
- Category
- Java
- Title
- read a file in java and store as integer array using buffered reader
- Category
- Java
- Title
- how to loop through an array
- Category
- Java
- Title
- arraylist to array java
- Category
- Java
- Title
- how to make a char uppercase in java
- Category
- Java
- Title
- how to take input in java
- Category
- Java
- Title
- java hashtable
- Category
- Java
- Title
- insert element into arraylist java
- Category
- Java
- Title
- how do you concatenate an int with a string in java
- Category
- Java
- Title
- system.arraycopy java
- Category
- Java
- Title
- java mockito print called methods
- Category
- Java
- Title
- java 8 seconds to days
- Category
- Java
- Title
- spannable string in android java for color
- Category
- Java
- Title
- compile java to jar in mac
- Category
- Java
- Title
- java read string input
- Category
- Java
- Title
- python to java converter
- Category
- Java
- Title
- big integer java
- Category
- Java
- Title
- e
- Category
- Java
- Title
- serialversionuid java
- Category
- Java
- Title
- java previous permutation
- Category
- Java
- Title
- how to return the first character in an array from a method java
- Category
- Java
- Title
- java get html from url
- Category
- Java
- Title
- scanner check if int
- Category
- Java
- Title
- generate random number java
- Category
- Java
- Title
- java execute for cycle parallel thread
- Category
- Java
- Title
- java how to get all threads
- Category
- Java
- Title
- java length of matrix
- Category
- Java
- Title
- j
- Category
- Java
- Title
- break for loop java
- Category
- Java
- Title
- How to make a class in Java?
- Category
- Java
- Title
- get tfidf score for a sentence
- Category
- Java
- Title
- int to binary java
- Category
- Java
- Title
- faire un timer en java
- Category
- Java
- Title
- how to create a button in java
- Category
- Java
- Title
- java valeur absolue
- Category
- Java
- Title
- java how to print an array
- Category
- Java
- Title
- online money transfer andhra bank
- Category
- Java
- Title
- best companies to workk in
- Category
- Java
- Title
- on click android studio not working
- Category
- Java
- Title
- abstract class java constructor
- Category
- Java
- Title
- generate a qr code in java
- Category
- Java
- Title
- how to compare current date and time with another date and time in android
- Category
- Java
- Title
- loop and save letters in a string java
- Category
- Java
- Title
- Building a maven EAR project and specifying the configuration of which projects to include, what is the element in the plugin configuration that contains Enterprise Java Bean Projects:
- Category
- Java
- Title
- place.getlatlng() returning null
- Category
- Java
- Title
- java swing draw centered text
- Category
- Java
- Title
- java check if file exists
- Category
- Java
- Title
- separateur JMenu swing java
- Category
- Java
- Title
- java stack push
- Category
- Java
- Title
- how to stop screen rotation in android code
- Category
- Java
- Title
- how to print to the console in java
- Category
- Java
- Title
- icon label java
- Category
- Java
- Title
- java read file from command line argument
- Category
- Java
- Title
- java define a generic class that produces
- Category
- Java
- Title
- how to convert string to double in android studio
- Category
- Java
- Title
- how to make a fixed size array in java
- Category
- Java
- Title
- Java.awt graphics tutorial
- Category
- Java
- Title
- error attribute fabattached not found
- Category
- Java
- Title
- java interface
- Category
- Java
- Title
- Error executing Maven. java.io.FileNotFoundException: The specified user settings file does not exist: /etc/java-8-openjdk
- Category
- Java
- Title
- how to set frame colo in java
- Category
- Java
- Title
- taking date as input in java
- Category
- Java
- Title
- how to make a button disapear on click in javafx
- Category
- Java
- Title
- java insertion sort
- Category
- Java
- Title
- BoxLayout java
- Category
- Java
- Title
- javafx polygon
- Category
- Java
- Title
- lastindexof java
- Category
- Java
- Title
- retrofit
- Category
- Java
- Title
- create jdbc connection in java
- Category
- Java
- Title
- java change boolean to opposite
- Category
- Java
- Title
- reverse linked list in java to get both head and tail
- Category
- Java
- Title
- java string to character stream
- Category
- Java
- Title
- threadsafe singleton pattern in java
- Category
- Java
- Title
- how to get array input in java
- Category
- Java
- Title
- validation list empty java
- Category
- Java
- Title
- wraping list to string java
- Category
- Java
- Title
- java comparable
- Category
- Java
- Title
- java bubble sort short circuit
- Category
- Java
- Title
- how to do a linear searc in java
- Category
- Java
- Title
- java strin to int
- Category
- Java
- Title
- java - get open ports
- Category
- Java
- Title
- random code
- Category
- Java
- Title
- how to create a draw Rectangle in java
- Category
- Java
- Title
- how to open a text file in java
- Category
- Java
- Title
- array declaration and initialization in java
- Category
- Java
- Title
- declareing a variable in java
- Category
- Java
- Title
- java code to concatinate integer
- Category
- Java
- Title
- for each loop java
- Category
- Java
- Title
- summary of operators java
- Category
- Java
- Title
- java exit
- Category
- Java
- Title
- getindexrequest elasticsearch
- Category
- Java
- Title
- how to append to an array in java
- Category
- Java
- Title
- how to check the lines in a file java scanner
- Category
- Java
- Title
- how to get orientation lock to portrait android stackoverflow
- Category
- Java
- Title
- spigot custom join message
- Category
- Java
- Title
- jar file not running after being compiled
- Category
- Java
- Title
- java for increment by 2
- Category
- Java
- Title
- what it means when create final variable in java
- Category
- Java