2012-04-22 17 views
0
public class Programming { 

    public static void main(String[] args) { 
     // Scanner scan = new Scanner(System.in); 

     int l = 0; 
     StringBuilder password = new StringBuilder(); 

     l = password.length(); 
     for (l = 1; l < 100; l++) { 
     if (l > 0 || l < 100) { 
      System.out.println("Your password has the correct length"); 
     } 
     } 
     if (l < 0 || l > 100) { 
     System.out.println("Your password does NOT have the correct length"); 
     } 

     for (int i = 0; i < 127; i++) { 

     } 
    } 
} 

我想知道如何运行一个循环来找出由PasswordGenerator类生成的第一个字符。文档here但每个字符只是一个0-127之间的标准ASCII码,之后我必须附加每个字符使其成为一个字符串。密码的长度在0到100之间(以上)。确定密码 - 循环找到字符 - 附加StringBuilder

+0

不知道是什么随机(;)在我的节目中是干什么的,只注意到它... – 2012-04-22 21:07:51

+0

你为什么通过密码长度检查100次循环? – JohnFx 2012-04-22 21:25:14

+0

另外,我在代码中看不到密码生成器。你只是在每次首先将密码设置为任何东西时测试一个空字符串。 – JohnFx 2012-04-22 21:26:08

回答

0

你不需要循环。

一旦找出如何调用密码生成器类来获取密码字符串中的值,只需使用下面的代码来获取第一个字符即可。

char firstCharacter = password.charAt(0)