let say i have fallowing javascript function-
function isDi开发者_如何学Cgit (c)
{ return ((c >= "0") && (c <= "9"))
}
function isAlphabet (c)
{
return ( (c >= "a" && c <= "z") || (c >= "A" && c <= "Z") )
}
How can i write same thing in java. Thanks.
Use java.lang.Character
class methods.
Respectively:
java.lang.Character.isLetter(c);
java.lang.Character.isDigit(c);
But if you want to make your own implementations:
boolean isAlpa(char c) {
return c >= 'A' && c <= 'Z'; /* single characters are
enclosed with single quotes */
}
public boolean isDigit(char c) {
return ((c >= '0') && (c <= '9'));
}
public boolean isAlphabet(char c) {
return ( (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') );
}
精彩评论