开发者

How can i convert this javascript function into java

开发者 https://www.devze.com 2023-04-08 06:47 出处:网络
let say i have fallowing javascript function- function isDi开发者_如何学Cgit (c) { return ((c >= \"0\") && (c <= \"9\"))

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') );
}
0

精彩评论

暂无评论...
验证码 换一张
取 消