2012-04-22 19 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)