循环生成的字符

时间:2012-04-29 22:22:08

标签: java loops

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)

1 个答案:

答案 0 :(得分: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;
        }
    }
}