【非正则】判断一个字符串是否由数字组成

package demo;

public class Isnum {
    public static void main(String[] args) throws Exception {
        String num = "123";
        System.out.println(isNumber(num));
    }

    public static boolean isNumber(String str) {
        char [] data = str.toCharArray();
        for (int x=0; x<data.length; x++) {
            if(data[x] > '9' || data[x] < '0') {
                return false;
            }
        }

        return true;
    }
 }

posted @ 2018-01-09 21:00  fanren224  阅读(183)  评论(0编辑  收藏  举报