fork(4) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.util.regex.Matcher;
  7. import java.util.regex.Pattern;
  8.  
  9. /* Name of the class has to be "Main" only if the class is public. */
  10. class Ideone
  11. {
  12. public static void main (String[] args) throws java.lang.Exception
  13. {
  14. Scanner x = new Scanner(System.in);
  15. String pattern = "^(249)?1\\d{8}$";
  16.  
  17. // Create a Pattern object
  18. Pattern r = Pattern.compile(pattern);
  19. while (true) {
  20. String line = x.nextLine();
  21. Matcher m = r.matcher(line);
  22. if (m.find()) {
  23. System.out.println("Found -> " + m.group());
  24. } else {
  25. System.out.println("Not Found");
  26. }
  27. }
  28.  
  29. }
  30. }
Runtime error #stdin #stdout #stderr 0.14s 321344KB
stdin
249189372837
249123476358
183526352
2431983645238
24924356383799
249212236472
1232345678
12345323
456278399
stdout
Found -> 249189372837
Found -> 249123476358
Found -> 183526352
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
stderr
Exception in thread "main" java.util.NoSuchElementException: No line found
	at java.util.Scanner.nextLine(Scanner.java:1540)
	at Ideone.main(Main.java:20)