Help using String and character analyzers such as isDigit() and isLetter()
For some reason the isDigit and isLetter are giving me an error.
PasswordReTest.java:41: cannot find symbol
symbol : method isLetter(int)
location: class java.lang.String
if (p.isLetter(i))
and
PasswordReTest.java:43: cannot find symbol
symbol : method isDigit(int)
location: class java.lang.String
if (p.isDigit(i))
Code java:
import java.lang.*;
import javax.swing.*;
import java.io.*;
public class PasswordReTest
{
static String p = new String("P");
static String pp = new String("p");
static int len = 0;
static int letter = 0;
static int number = 0;
static int i = 0;
static char ch;
public static void main(String[] args)
{
passwordGet();
passwordLengthTest();
passwordCharTest();
passwordValidate();
JOptionPane.showMessageDialog(null, "Thank you for using the program");
}
public static void passwordGet()
{
String p = new String(JOptionPane.showInputDialog(null,"Please Enter" +
" Your Password: "));
}
public static void passwordLengthTest()
{
len = p.length();
if (len > 10 || len < 6)
{
JOptionPane.showMessageDialog(null, "Please make sure your password is" +
" between 6 and 10 charcters long", "Error", JOptionPane.ERROR_MESSAGE);
passwordGet();
}
else
{
for(int i = 0; i < len; i++);
{
if (p.isLetter(i))
letter++;
else if (p.isDigit(i))
number++;
else
JOptionPane.showMessageDialog(null,"Invalid Charcter. Please enter only" +
"letters & numbers", "Error", JOptionPane.ERROR_MESSAGE);
}
}
}
public static void passwordCharTest()
{
if(letter <= 0)
{
JOptionPane.showMessageDialog(null, "Error", "Your password must contain" +
" at least one Letter.", JOptionPane.ERROR_MESSAGE);
}
else if(number <= 0)
{
JOptionPane.showMessageDialog(null, "Error", "Your password must" +
" contain at least one Digit", JOptionPane.ERROR_MESSAGE);
}
else
{
passwordValidate();
}
}
public static void passwordValidate()
{
String pp = new String(JOptionPane.showInputDialog(null, "Please enter the" +
" password again: "));
if (pp.equals(p))
JOptionPane.showMessageDialog(null,"Password Accepted :)");
}
}
Any ideas? Thanks in advance. :)
Re: Help using String and character analyzers such as isDigit() and isLetter()
Where in the API is isDigit and isLetter defined for String? Perhaps you are thinking of the Character classes static methods.