Can any one solve this error ?

January 15, 2011 at 06:03:42
Specs: Windows XP
Can any one solve this error?I am doing it in Java
Permutation with repetition
[code]

public class Test {
public static void main(String... args) {

// Limit imposed by Integer.toString(int i, int radix) which is used
// for the purpose of this demo.
final String chars = "0123456789abcdefghijklmnopqrstuvwxyz";

int wordLength = 3;
char[] alphabet = { 'a', 'b', 'c' };

for (int i = 0; i < Math.pow(wordLength, alphabet.length); i++) {

String str = Integer.toString(i, alphabet.length);

String result = "";
while (result.length() + str.length() < wordLength)
result += alphabet[0];

for (char c : str.toCharArray())
result += alphabet[chars.indexOf(c)];

System.out.println(result);
}
}
}

[/code]


Output would be:

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


Thank you


See More: Can any one solve this error ?

Report •

#1
January 21, 2011 at 01:50:20
hi
but i didnot understand you want the output to be like you write on your question

Report •
Related Solutions


Ask Question