从键盘输入一串字符,判断它是否为数字,有这样的方法么?

解决方案 »

  1.   


    //没有现成的!自己写
    public class Client {    public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            String s = sc.nextLine();
            boolean bo = isNumber(s);
        }    public static boolean isNumber(String s) {        try {
                int i = Integer.valueOf(s);
            } catch (NumberFormatException e) {
                return false;
            }
            return true;
        }
    }