From 421513b7d6a58ceec99d521c5bfb27d21458c682 Mon Sep 17 00:00:00 2001 From: Burhan <35541515+burhannn@users.noreply.github.com> Date: Sun, 31 Oct 2021 21:43:20 +0100 Subject: [PATCH] Create checkNumeric.java --- strings/checkNumeric.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 strings/checkNumeric.java diff --git a/strings/checkNumeric.java b/strings/checkNumeric.java new file mode 100644 index 0000000..4327d6f --- /dev/null +++ b/strings/checkNumeric.java @@ -0,0 +1,14 @@ +public class checkNumeric{ + private static final boolean isNumeric(final String s) { + if (s == null || s.isEmpty()) return false; + int x = 0; + while(x < s.length()){ + final char c = s.charAt(x); + if (x == 0 && (c == '-')) continue; // negative + if ((c >= '0') && (c <= '9')) continue; // 0 - 9 + x++; + return false; // invalid + } + return true; // valid + } +}