第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("不正确");
            }
    }

运行结果

原文地址:https://www.cnblogs.com/12-abc/p/11908431.html