我正在尝试制作一个函数来输出字符串的所有可能情况。该函数必须输出字符串的每个变体并为该变体保留一个计数器。例如,没有特定的顺序:
Cd
C>d
C>D
CD
cd
cD
c>D
c>d
到目前为止,我有这个:
public int allCase(String data)
{
int count=0; // counter for the amount of case changes completed
int size= data.length();// length of incoming string
char c[]= data.toLowerCase().toCharArray();
double maxpos=Math.pow(2,size);
System.out.println("Maximum possibilities= "+maxpos);
for(int i=0;i<size;i++)
{
if (c[i]> 33 && c[i]<64) // if the character is special characters !@#$%^&*()_<>?,./
{ // prints characters in front and behind of special character
System.out.println( data.substring(0,i)+((char)(c[i]+16))+data.substring(i+1));
}
else{
// output the string variation
}
count++;
}
return count;
}