第13次作业

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

/*从键盘接受一个邮箱
* 然后和定义的正则表达式 想匹配
* */
package comm;
import java.util.Scanner;
public class Test33 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("请输入一个邮箱");
String regex="\w+@\w+(\.\w{2,3})*\.\w{2,3}";
String str1=sc.nextLine();
if(str1.matches(regex)){//判断字符串变量是否与正则表达式匹配;
System.out.println("这个邮箱"+str1+"是合法的邮箱");
}else{
System.out.println("这个邮箱"+str1+"不是合法的邮箱");
}
}
}

运行结果

原文地址:https://www.cnblogs.com/LJTQ/p/11923936.html