第十三次作业

题目:定义判断电子邮箱的正则表达式,判断输入的字符串是否为电子邮箱地址。

 源代码

package zuoye;
import java.util.*;
public class YouXiang {
public static void main(String[]args){
    System.out.println("请输入要验证的邮箱");
    Scanner reader=new Scanner(System.in);
     String str=reader.nextLine();
     String regex="\\w*@[a-z0-9]{0,}[.]\\w{2,3}";
     if(str.matches(regex)){
         System.out.println(str+"是一个合法的邮箱地址");
     }else{
         System.out.println(str+"不是一个合法的邮箱地址");
     }
    
}
}

运行截图

posted @ 2019-11-22 19:00  长安别故里  阅读(87)  评论(0编辑  收藏  举报