JAVA8. 邮箱验证
描述
输入描述
任意字符串输出描述
根据输入的邮箱格式判断其合法于不合法,若输入字符串符合邮箱格式则输出邮箱格式合法,否则输出邮箱格式不合法示例1
输入:
123123@nowcoder.com
输出:
邮箱格式合法
示例2
输入:
123123
输出:
邮箱格式不合法
Java 解法, 执行用时: 13ms, 内存消耗: 9516KB, 提交时间: 2022-07-21
import java.util.Scanner; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String str = br.readLine(); String emailMatcher="[a-zA-Z0-9]+@[a-zA-Z0-9]+\\.[a-zA-Z0-9]+"; //write your code here...... System.out.println(str.matches(emailMatcher)?"邮箱格式合法":"邮箱格式不合法"); } }
Java 解法, 执行用时: 13ms, 内存消耗: 9568KB, 提交时间: 2022-07-03
import java.util.Scanner; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String str = br.readLine(); String emailMatcher="[a-zA-Z0-9]+@[a-zA-Z0-9]+\\.[a-zA-Z0-9]+"; //write your code here...... if(str.matches(emailMatcher)){ System.out.println("邮箱格式合法"); }else{ System.out.println("邮箱格式不合法"); } } }
Java 解法, 执行用时: 13ms, 内存消耗: 9696KB, 提交时间: 2022-07-29
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws IOException{ BufferedReader b = new BufferedReader(new InputStreamReader(System.in)); String str =b.readLine(); String emailMatcher="[a-zA-Z0-9]+@[a-zA-Z0-9]+\\.[a-zA-Z0-9]+"; //write your code here...... if(str.matches(emailMatcher)){ System.out.println("邮箱格式合法"); } else{ System.out.println("邮箱格式不合法"); } } }
Java 解法, 执行用时: 13ms, 内存消耗: 9700KB, 提交时间: 2022-05-25
import java.util.Scanner; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String str = br.readLine(); String emailMatcher="[a-zA-Z0-9]+@[a-zA-Z0-9]+\\.[a-zA-Z0-9]+"; //write your code here...... if(str.matches(emailMatcher)){ System.out.println("邮箱格式合法"); }else{ System.out.println("邮箱格式不合法"); } } }
Java 解法, 执行用时: 13ms, 内存消耗: 10568KB, 提交时间: 2022-05-14
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String str = br.readLine(); if(str.endsWith(".com")&&str.contains("@")&&(str.startsWith("@")==false)){ System.out.println("邮箱格式合法"); }else { System.out.println("邮箱格式不合法"); } } }