0
public class Driver {

public static void main(String[] args) {


    int length=0;
    int MaxNumber=100;
    StringBuilder password = new StringBuilder();





    do {
        if (PasswordGenerator.matchLength (length)) {
            break;
        }
        length++; // length is randomly picked
    } while (length < MaxNumber );   // or <100
    System.out.println("The length of the character string is " + length);


    int index = 0;
    char f = 0;


    for (char d = 0; d < 127; d++) {
        if(PasswordGenerator.matchCharAt(d, index)) {
            password.append(d);
            System.out.println("Hey! Char at " + index + " is " + d);
            d++;
        }
    }



}
}

所以我找到了如何通过循环找到我随机生成的密码的第一个字符,并且想知道如何通过使用该循环或另一个循环来提供它来查找密码中的其他字符。字符跟随循环的长度,这也是随机生成的。PasswordGenerator 类的文档在这里.. (http://www.technology.heartland.edu/faculty/todds/csci130/assignments/A5_password/doc/index.html)

4

1 回答 1

0

将 的值更改为index您要查找的字符的位置。如果您想找到所有这些,那么...

for(int j=0; j < length; j++)
{
      for (char d = 0; d < 127; d++) 
      {
        if(PasswordGenerator.matchCharAt(d, j)) 
        {
            password.append(d);
            System.out.println("Hey! Char at " + index + " is " + d);

            // No sense in incrementing d and going through all of them
            // You found it already, break this loop
            break;
        }
    }
}
于 2012-04-29T22:27:19.697 回答