Can someone help me to understand the logic what is happening at this line
findResult(record, output + record[i], n - 1, size);
in the following code.
public class Combinations
{
public void findResult(char[] record, String output, int n, int size)
{
if (output.length() > 0)
{
// Display output
System.out.println(output);
}
if (n == 0)
{
return;
}
for (int i = 0; i < size; ++i)
{
// Find result using recursion
findResult(record, output + record[i], n - 1, size);
}
}
public static void main(String[] args)
{
Combinations task = new Combinations();
// Character element
char[] record = {
'A' , 'T' , 'M' , '@' , '$'
};
// Get number of element in record set
int size = record.length;
// Length of generated string
int n = 3;
task.findResult(record, "", n, size);
}
}