brainfrz icon

Untitled

brainfrz | PRO | 03/02/16 01:02:00 AM UTC | 0 ⭐ | 760 👁️ | Never ⏰ | []
Java |

840 B

|

None

|

0 👍

/

0 👎

public static boolean hasUpperCase(String str) throws PasswordUpperCase
{  
    boolean hasUpperCase = false;
 
    //checks the password for an upper case letter
    for (char c : str.toCharArray())
    {
        if(Character.isUpperCase(c))
        {
            hasUpperCase = true;
        }
    }
    
    if (!hasUpperCase)
    {
        throw new PasswordUpperCase();
    }
}
 
/*************OR************/
 
public static boolean hasUpperCase(String str) throws PasswordUpperCase
{  
    boolean hasUpperCase = false;
 
    //checks the password for an upper case letter
    for (int c = 0; c < str.length() && !hasUpperCase; c++)
    {
        if(Character.isUpperCase(c))
        {
            hasUpperCase = true;
        }
    }
    
    if (!hasUpperCase)
    {
        throw new PasswordUpperCase();
    }
}

Comments