我的两种密码验证方法有问题。方法 hasDigitsAndLetters 应该检查字符串的所有字符是否都是数字和字母,第二种方法 hasTwoDigits 应该检查传递中是否至少有两个数字,但问题是对于预期的结果 true 他们是 ruturning错误的。如果有人可以提供帮助。这是代码。
//check if the whole string consists of digits and letters
    public static boolean hasDigitsAndLetters(String pass)
    {
        for(int i=0; i<pass.length(); i++)
        {
            if(!Character.isLetterOrDigit((i)))
            {
                return false;
            }
        }
        return true;
    }
    // check whether the password has at least 2 digits
    public static boolean hasTwoDigits(String pass)
    {
        int counter = 0;
        for(int i=0; i<pass.length(); i++)
        {
            if(Character.isDigit(i))
            {
                counter ++;
            }
        }
        System.out.println("Number of digits: " + counter);
        if(counter >= 2)
        {
            return true;
        }
        return false;
    }