Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Help using String and character analyzers such as isDigit() and isLetter()

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default 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))

    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.


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default 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.

Similar Threads

  1. Replies: 5
    Last Post: April 22nd, 2013, 07:27 AM
  2. Replies: 2
    Last Post: October 22nd, 2011, 01:34 AM
  3. Trouble with the use of isDigit and isLetter
    By SeanEE89 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: October 7th, 2011, 04:41 PM
  4. How to convert or break String into Character
    By Bharath12 in forum Java Theory & Questions
    Replies: 2
    Last Post: September 14th, 2011, 11:41 PM
  5. Replies: 1
    Last Post: February 4th, 2010, 04:23 PM