Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {
    public static boolean containsOnlyNumbers(String str) {
        if (str == null || str.length() == 0) {
            return false;
        }

        //Replace '-'
        str = str.replaceAll("-", "");

        for (int i = 0; i < str.length(); i++) {
            if (str.charAt(i) == '.')
                continue;
            if (!Character.isDigit(str.charAt(i))) {
                return false;
            }
        }

        return true;
    }
}