fork(1) download
  1. class OnlyDigits
  2. {
  3. public static void main (String[] args) throws java.lang.Exception
  4. {
  5. String[] corpus = new String[]{
  6. "123",
  7. "",
  8. "abc123def",
  9. "abc",
  10. "123.456",
  11. "123 456",
  12. };
  13. for(String s:corpus) {
  14. boolean b = s.matches("[0-9]*");
  15. System.out.println( s + " => " + b);
  16. }
  17. }
  18. }
Success #stdin #stdout 0.1s 320512KB
stdin
Standard input is empty
stdout
123 => true
 => true
abc123def => false
abc => false
123.456 => false
123 456 => false