题解 | #邮箱验证#
邮箱验证
http://www.nowcoder.com/practice/8f908eeee4aa412ca88304f0acbaa1f9
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String str = scanner.next();
String emailMatcher="[a-zA-Z0-9]+@[a-zA-Z0-9]+\\.[a-zA-Z0-9]+";
//write your code here......
if(str.matches(emailMatcher))//此题考察的是正则表达式与matches的用法
//[a-zA-Z0-9]+表示中括号里面的内容至少出现一次,
//\\.用转义字符来表示.,因为.在正则表达式中表示任意字符,必须用转义才能将.表示出来
System.out.println("邮箱格式合法");
else
System.out.println("邮箱格式不合法");
}
}