fork(1) 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.Scanner;
  7.  
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. Scanner input=new Scanner(System.in);
  13. String text;
  14. String cha;
  15.  
  16. System.out.println("Enter a Serial number: ");
  17. text=input.nextLine();
  18.  
  19. if(text.matches("[A-Za-z0-9]+(-[A-Za-z0-9]+){2}")){
  20. System.out.println("Serial number "+text+" verification \nValid");
  21. System.out.println("Enter a wildchar character: ");
  22. cha=input.nextLine();
  23. text= text.replaceAll("[A-Za-z0-9]", cha);
  24. System.out.println("Masked serial: "+text);
  25. } else if(text.matches(".*[^-A-Za-z0-9].*")) {
  26. System.out.println("Invalid. Serial should only contain letters, numbers, and dashes(-)");
  27. } else if(text.matches("[A-Za-z0-9]+(-+[A-Za-z0-9]+){2,}")) {
  28. System.out.println("Invalid. There should be exactly 2 non-consecutive dashes in the middle. ");
  29. }
  30. }
  31. }
Success #stdin #stdout 0.06s 2184192KB
stdin
1-2-3
*
stdout
Enter a Serial number: 
Serial number 1-2-3 verification 
Valid
Enter a wildchar character: 
Masked serial: *-*-*