You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
764 B
Java

Letter combinations recursion
public class LetterCombinationsRecursion {
private static String sum = "";
public static void main( String[] argv ) {
long l = System.currentTimeMillis();
printAlphabetCombinations( 4, "" );
System.out.println( "Time:" + ( System.currentTimeMillis() - l ) / 1000 + " sec" );
}
public static void printAlphabetCombinations( int recurseCounter, String current ) {
String temp = current;
if( recurseCounter == 0 ) {
System.out.println( temp );
return;
}
else {
recurseCounter--;
for( int i = 0; i < 26; i++ ) {
temp = current + (char) ( 65 + i );
printAlphabetCombinations( recurseCounter, temp );
}
}
}
}