question. thanks in advance for your help

Printable View

• 11-22-2010, 10:28 AM
farahm
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?
• 11-22-2010, 11:02 AM
JosAH
Quote:

Originally Posted by farahm
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:

Code:

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

kind regards,

Jos
• 11-22-2010, 11:19 AM
farahm
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
• 11-22-2010, 11:46 AM
JosAH
Quote:

Originally Posted by farahm
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:

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
• 11-22-2010, 12:25 PM
farahm
thank you so much it worked.