You are on page 1of 3

Act 1:

import java.util.Scanner;

public class labRecActOne_Garlit {

public static void TowerOfHanoi(int x, char j, char k, char l, char m) {

if (x == 0)

return;

TowerOfHanoi(x - 1, j, m, l, k);

System.out.println("Disc " + x + " from " + j + " to " + m);

TowerOfHanoi(x - 1, m, j, l, k);

public static void main(String[] args)

System.out.print("Enter number of Disk/s :");

Scanner s = new Scanner(System.in);

int NumberOfDiscs = s.nextInt();

TowerOfHanoi(NumberOfDiscs, 'J', 'K', 'L', 'M');

Output:
Act 2:
import java.util.Scanner;

public class labRecActTwo_Garlit {


private static void permutations(String candidate, String remaining)
{
if (remaining.length() == 0) {
System.out.println(candidate);
}

for (int a = 0; a < remaining.length(); a++)


{
String newCandidate = candidate + remaining.charAt(a);

String newRemaining = remaining.substring(0,a) + remaining.substring(a + 1);

permutations(newCandidate, newRemaining);
}
}

public static void main(String[] args)


{
Scanner type = new Scanner(System.in);
String x;
System.out.print("Enter 4 letter words: ");
x = type.nextLine();
permutations("", x);
}
}

Output:

You might also like