我应该在一个不同的类中创建一个方法,该方法接受字符串输入并:“验证字符串表示8个符号,包括字母(大写和小写),数字和特殊符号,例如#$&_。”
到目前为止,这是我的代码。
public static boolean validSSN(String SSN)
{
int length = SSN.length();
boolean flag = false;
if(length == 11)
{
if(SSN.matches("^\\d{3}[-]{1}\\d{2}[-]{1}\\d{4}")) flag = true;
}
return flag;
}
答案 0 :(得分:-1)
我可能已经找到了解决方法:
(defun identity-groups (list &key (test #'eql) (key #'identity))
"Collect adjacent items in LIST that are the same. Returns a list of lists."
(labels ((travel (tail group groups)
(cond ((endp tail) (mapcar #'nreverse (cons group groups)))
((funcall test
(funcall key (car tail))
(funcall key (car group)))
(travel (cdr tail) (cons (car tail) group) groups))
(t (travel (cdr tail) (list (car tail)) (cons group groups))))))
(nreverse (travel (cdr list) (list (car list)) nil))))
代替
(identity-groups '(1 2 2 2 3 3 3 4 3 2 2 1))
-> ((1) (2 2 2) (3 3 3) (4) (3) (2 2) (1))
;; Collect numbers in groups of even and odd:
(identity-groups '(1 3 4 6 8 9 11 13 14 15) :key #'oddp)
-> ((1 3) (4 6 8) (9 11 13) (14) (15))
;; Collect items that are EQ:
(identity-groups (list 1 1 2 2 (list "A") (list "A")) :test 'eq)
-> ((1 1) (2 2) (("A")) (("A")))