第13次作业--邮箱的正则表达式
-
题目
定义判断电子邮箱的正则表达式,判断输入的字符串是否为电子邮箱地址。
-
源程序
Test.java
1 import java.util.*; 2 public class Test { 3 4 public static void main(String[] args) { 5 // TODO Auto-generated method stub 6 Scanner in = new Scanner(System.in); 7 System.out.println("输入您的邮箱:"); 8 9 while(in.hasNext()) { 10 String str1 = in.next(); 11 String str2 = "[a-zA-Z0-9-_]+@[a-zA-Z0-9]+(.com|.cn)"; 12 13 if(str1.matches(str2)) 14 System.out.println("邮箱合格"); 15 else 16 System.out.println("邮箱不合格"); 17 } 18 } 19 20 }
-
运行结果


浙公网安备 33010602011771号