码迷,mamicode.com
首页 > 其他好文 > 详细

华为OJ:2192 邮箱地址合法性校验

时间:2014-07-10 19:59:35      阅读:209      评论:0      收藏:0      [点我收藏+]

标签:style   java   for   line   new   amp   

注意输入的字符串里面可能有空格,所以要nextLine()而不是next(),其他一个个验证就好了,@要计算次数,多了少了都不行。

import java.util.Scanner;
public class eMailchecked {
	public static void main(String args[]){
		Scanner input=new Scanner(System.in);
		String s=input.nextLine();
		int countAt=0;
		if(s.charAt(s.length()-1)!='m'||s.charAt(s.length()-2)!='o'||s.charAt(s.length()-3)!='c'||s.charAt(s.length()-4)!='.'){System.out.println('0');return;}
		for(int i=0;i<s.length();i++){
			if(s.charAt(i)=='@')countAt++;
			if(countAt==2||s.charAt(i)==' '||!((s.charAt(i)<='9'&&s.charAt(i)>='1')||(s.charAt(i)<='z'&&s.charAt(i)>='a')||(s.charAt(i)<='Z'&&s.charAt(i)>='A')||s.charAt(i)=='.'||s.charAt(i)=='@'||s.charAt(i)=='_')){System.out.println('0');return;}
		}
		if(countAt!=1){System.out.println('0');return;}
		System.out.println("1");
	}
}

华为OJ:2192 邮箱地址合法性校验,布布扣,bubuko.com

华为OJ:2192 邮箱地址合法性校验

标签:style   java   for   line   new   amp   

原文地址:http://blog.csdn.net/whu_sky/article/details/37595661

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!