i am working on a program where the user enters a number and the computer will generate N number of characters and print them in all combonations. For example:
enter number: 3
aaa aab aac aba abb abc aca acb acc
baa bab bac bba bbb bbc bca bcb bcc
caa cab cac cba cbb cbc cca ccb ccc
I have made the program build the array and randomize the characters however i dont know how to use recursion to print all the combos. Here is what i have so far:
import cs1.Keyboard;
import java.util.Random;
public class Letter
{
public static void main(String[] args)
{
System.out.println("How many characters do you want");
int number = Keyboard.readInt();
char[] list = new char[number];
Random generator = new Random();
for(int index = 0; index < list.length; index++)
{
int temp = generator.nextInt(26) + 65;
list[index] = (char) temp;
}
//check if all characters are different
for(int index = 0; index < list.length-1; index++)
{
if(list[index] == (list[index+1]))
{
int temp = generator.nextInt(26) + 65;
list[index+1] = (char) temp;
index=0;
}
}
I believe recursion would be the best solution but i dont know how to use it to print the answer. Any help would be great. thanx