第13次作业

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

代码

package com;
import java.util.*;
import java.text.ParseException;
import java.text.SimpleDateFormat;
public class N {
    public static void main(String[] args)throws ParseException{
        Scanner s=new Scanner(System.in);
        System.out.println("请输入你的邮箱");
        String email=s.nextLine();
        String re="\\w+[@]\\w+[.]\\w+";
        if(email.matches(re)){
            System.out.println("正确");
        }
        else
            System.out.println("不正确");
            }
    }

运行结果

posted @ 2019-11-22 19:32  纪骁宵  阅读(65)  评论(0编辑  收藏  举报