Results 1 to 5 of 5
  1. #1
    farahm is offline Member
    Join Date
    Nov 2010
    Location
    Beirut, Lebanon
    Posts
    36
    Rep Power
    0

    Default question. thanks in advance for your help

    im writing a password check program in java now i sorted out that i need at least 6 letters and maximum 15, and at least a letter and a digit but i need to sort out the rule "not to end the password with '99'. '99' is lowercase c.
    i started that: if 2 and 3 are true(1 letter/1 digit),
    but how do i check if the last letter is c?

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,457
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by farahm View Post
    im writing a password check program in java now i sorted out that i need at least 6 letters and maximum 15, and at least a letter and a digit but i need to sort out the rule "not to end the password with '99'. '99' is lowercase c.
    i started that: if 2 and 3 are true(1 letter/1 digit),
    but how do i check if the last letter is c?
    The String class has an endsWith(String suffix) method, so this:

    Java Code:
    String yourString= ...;
    boolean ewc= yourString.endsWith("c");
    ... would solve your problem.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    farahm is offline Member
    Join Date
    Nov 2010
    Location
    Beirut, Lebanon
    Posts
    36
    Rep Power
    0

    Default

    im not allowed to use this method yet since it has not been taught to us.
    it says it cannot be a series of alphabetical characters ending with '99' and i realized they meant the letters 99 so i started with if it is all characters and want to check the last two and wrote this:
    if (var == true) //all letters
    {
    if (Character.isDigit(S.charAt(S.length()-2)) && Character.isDigit(S.charAt(S.length()-1))) //last two digits
    {

    }


    }
    }
    how do i check if the last two digits are 99?
    thanks in advance for your help

  4. #4
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,457
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by farahm View Post
    how do i check if the last two digits are 99?
    It you're not allowed to use the endsWith( ... ) method you have to check these two characters yourself:

    Java Code:
    String s= ...; // your String
    int e= s.length(); // the length of your String
    
    if (e >= 2 && s.charAt(e-1) == '9' && s.charAt(e-2) == '9')
       // here s contains at least 2 chars and the two last chars are a '9'
    It's straight foreward isn't it?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    farahm is offline Member
    Join Date
    Nov 2010
    Location
    Beirut, Lebanon
    Posts
    36
    Rep Power
    0

Similar Threads

  1. Question mark colon operator question
    By orchid in forum Advanced Java
    Replies: 9
    Last Post: 12-19-2010, 08:49 AM
  2. small problem, thanks in advance for your help
    By farahm in forum New To Java
    Replies: 4
    Last Post: 11-22-2010, 09:26 AM
  3. How to advance ?
    By House in forum New To Java
    Replies: 14
    Last Post: 08-29-2010, 03:29 AM
  4. Advice for Advance projects?
    By suyash89 in forum Advanced Java
    Replies: 7
    Last Post: 01-02-2010, 10:51 PM
  5. One question..
    By LuC2 in forum New To Java
    Replies: 3
    Last Post: 08-25-2009, 01:29 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •