Java String with only digit by ASCII code

Description

Java String with only digit by ASCII code


public class Main {
    public static void main(String[] argv) throws Exception {
        String str = "";
        System.out.println(isNumeric(str));
    }/*from   ww  w. j a  v  a 2 s  . c  o m*/

    public static boolean isNumeric(String str) {
        for (int i = str.length(); --i >= 0;) {
            int chr = str.charAt(i);
            if (chr < 48 || chr > 57)
                return false;
        }
        return true;
    }
}



PreviousNext

Related