问题:我该如何消除这个错误或修复我的方法以使其返回密码?
public static char[]chars = {'a','b','c','d','e','f','g','h','i','j','k','l','m',
'n','o','p','q','r','s','t','u','v','w','x','y','z','0','1','2','3','4','5',
'6','7','8','9','!','@','$','%','^','&'};
public static String generatePassword(Random rand, String password, int position, int size) //this method must return a result of type String
{
boolean isLowerCase = rand.nextBoolean();
int randomChar = rand.nextInt(chars.length);
char c = chars[randomChar];
if(position == size) //base case
{
return password; //string is returned here?
}
if(isLowerCase)
{
generatePassword(rand, password + c, position + 1, size);
}
else //its either upper or lower case
{
generatePassword(rand, password + Character.toUpperCase(c), position + 1, size);
}
return generatePassword(rand, password + c, position + 1, size);(以及其他的else条件)是什么意思? - MadProgrammer