Java - Write code to check if a string is A Number via Long.parseLong()

Requirements

Write code to check if a string is A Number via Long.parseLong()

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        String string = "book2s.com";
        System.out.println(isANumber(string));
    }/* www .j av a2 s .  c  o m*/

    public static boolean isANumber(String string) {
        try {
            Long.parseLong(string);
            return true;
        } catch (NumberFormatException e) {
            return false;
        }
    }
}

Related Exercise