Java isLetterOrDigit() la méthode, appel isdigit(), isLetter()

Je suis à essayer de comprendre comment vérifier un String pour vérifier si elle avait au moins une lettre et un nombre à la. Je vais être franc que ce sont les devoirs et je suis un peu confus.

Il existe une méthode isLetterOrDigit() méthode semble que ce serait la bonne méthode, mais je suis undure que la façon dont je voudrais mettre en œuvre dans mon code. Ici c'est le code que j'utilise ci-dessous:

import javax.swing.JOptionPane;

public class Password
{
    public static void main(String[] args)
    {

    String initialPassword;
    String secondaryPassword;
    int initialLength;

    initialPassword = JOptionPane.showInputDialog(null, "Enter Your Passowrd.");

    initialLength = initialPassword.length();

    JOptionPane.showMessageDialog(null, "initialLength = " + initialLength);

    while (initialLength < 6 || initialLength > 10)
    {
        initialPassword = JOptionPane.showInputDialog(null, "Your password does not meet the length requirements. It must be at least 6 characters long but no longer than 10.");
        initialLength = initialPassword.length();
    }

    //Needs to contain at least one letter and one digit

    secondaryPassword = JOptionPane.showInputDialog(null, "Please enter your password again to verify.");

    JOptionPane.showMessageDialog(null, "Initial password : " + initialPassword + "\nSecondar Password : " + secondaryPassword);

    while (!secondaryPassword.equals(initialPassword))
    {
        secondaryPassword = JOptionPane.showInputDialog(null, "Your passwords do not match. Please enter you password again."); 
    }

    JOptionPane.showMessageDialog(null, "The program has successfully completed."); 

    }
}

Je veux mettre en œuvre une méthode où la section des commentaires est en utilisant soit le isDigit(), isLetter(), ou isLetterOrDigit() méthodes, mais je ne sais pas comment le faire.

Toute orientation serait appréciée. Merci d'avance pour l'aide.

InformationsquelleAutor cdo | 2011-12-03