列表

详情


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("邮箱格式不合法");
        }
    }
}

上一题