Hey guys, I have the assignment of writing the Towers of Hanoi program then testing it. I already got help measuring the time of the program, but that is not what my professor wanted he wanted to count the iterations. I can't get it down, my program will run but it will not print out correctly.
This is the code I was using.
import TerminalIO.KeyboardReader;
public class towers
{
public static void main(String[] args)
{
KeyboardReader reader = new KeyboardReader();
int numberofRings = reader.readInt("Enter number of Rings: ");
move (numberofRings, 1, 3, 2);
}
static void move(int n, int i, int j, int k)
{
int count = 0;
if (n > 0)
{
move(n - 1, i, k, j);
System.out.println("Move ring " + n + "from peg" + i + "to" + j);
move(n - 1, k, j, i);
count++;
}
System.out.println(count+ "Is the number of Moves");
}
}
And it keeps printing out
0 Is the number of Moves
Move ring 1 from peg 1 to 2
0 Is the number of Moves
1 Is the number of Moves
Move ring 2 from peg 1 to 3
0 Is the number of Moves
and repeating
Any help would be greatly appreaciated