第13次作业——邮箱

一、题目

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

二、代码

import java.util.*;
public class email {
	
	public static void main(String[] args) {
		System.out.println("请输入需要判断的邮箱地址:");
		Scanner r=new Scanner(System.in);
		String s=new String();
		s=r.nextLine();
		
		String mail="\w{0,}@[a-z0-9]{0,}[.]((com)|(cn)){1}";//正则表达式判断规则
		
		if(s.matches(mail)){
			System.out.println(s+"符合邮箱命名规则");
		}
		else{
			System.out.println(s+"不符合邮箱命名规则");
		}
	}

}

  

三、运行结果

原文地址:https://www.cnblogs.com/whohow/p/11918927.html