Reputation: 11028
let say i have fallowing javascript function-
function isDigit (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.
Upvotes: 0
Views: 524
Reputation: 20663
public boolean isDigit(char c) {
return ((c >= '0') && (c <= '9'));
}
public boolean isAlphabet(char c) {
return ( (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') );
}
Upvotes: 3
Reputation: 7945
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 */
}
Upvotes: 3