TowerOfHanoi | TestCases

Test Cases are not passing for TowerofHanoi assignment. What is the problem in my code? It is working fine in dos prompt.

import java.util.Scanner;

public class Main {

public static void main(String str[]){
	Scanner sc = new Scanner(System.in);
	int input = sc.nextInt();
	//towerOfHanoi(3,"S","D","T");
	// A is the source, B is the temporary, C is the destination
	towerOfHanoi(input,"A","C","B");
}

static void towerOfHanoi(int disc, String source, String destination, String temporary){
	
	if ( disc == 1 )
	{
		String s = String.format("Moving ring %d from %s to %s",disc,source,destination);
		System.out.println(s);
		//return;
	}
	else
	{
		towerOfHanoi(disc-1,source,temporary,destination);
		String s = String.format("Moving ring %d from %s to %s",disc,source,destination);
		System.out.println(s);
		towerOfHanoi(disc-1,temporary,destination,source);
	}
	
	//return;
}

}

Hey @connectrajanjain When you’re calling towerOfHanoi from main instead of 3 you need to pass input there.(input,β€œA”,β€œC”,β€œB”,)

If you have noticed,
//towerOfHanoi(3,β€œS”,β€œD”,β€œT”);
is commented.

I am using
towerOfHanoi(input,β€œA”,β€œC”,β€œB”);

Am i missing something???

HEy @connectrajanjain in the base case of program write disc == 0 in the condition and remove SysO statement from the base case.

Modified Code. Disc also made to zero and removed print statement from base condition but still no luck. Test Cases are still failing.

import java.util.Scanner;
public class Main {
	public static void main(String str[]){
		Scanner sc = new Scanner(System.in);
		int input = sc.nextInt();
		//towerOfHanoi(3,"S","D","T");
		// A is the source, B is the temporary, C is the destination
		towerOfHanoi(input,"A","C","B");
	}
	
	static void towerOfHanoi(int disc, String source, String destination, String temporary){
		
		if ( disc == 0 )
		{
			//String s = String.format("Moving ring %d from %s to %s",disc,source,destination);
			//System.out.println(s);
			return;
		}
		else
		{
			towerOfHanoi(disc-1,source,temporary,destination);
			String s = String.format("Moving ring %d from %s to %s",disc,source,destination);
			System.out.println(s);
			towerOfHanoi(disc-1,temporary,destination,source);
		}
		
		//return;
	}
	
}

Hey @connectrajanjain Instead of using A,B and C;
use
for A use T1
for C use T2
for B use T3