邮箱的判断及数字检验

package test;
import java.util.*;
public class test {
	/*
	 * 判断邮箱格式
	 */
	String[] sMail= {"@","."};
	char[] cNum = {'1','2','3','4','5','6','7','8','9','0'};
	   public boolean isMail(String sPara){   	
		   for(int i=0;i<sMail.length;i++){   	  
			   if(sPara.indexOf(sMail[i])==-1)   //indexOf表示首次出现的位置	    
				   return false;   	     	
			   }   
		   return true;   
			   }
/*
 * 判断是否为数字
 */
	   public boolean isNum(String sPara) {
		   int L=sPara.length();
		   int l=cNum.length;
		   for(int i=0;i<L;i++) {
			   char nn=sPara.charAt(i);
			   boolean nnn=false;
			   for(int j=0;i<l;j++) {
				   if(nn==cNum[j]) {
					   nnn=true;
					   break;
				   }
			   }
			   if(!nnn) {
				   return false;
			   }
		   }
		   return true;
	   }
	   
	public static void main(String[] args) {
		test aa=new test();
		@SuppressWarnings("resource")
		/*
		 * 添加此注解除属性上的黄色警告
		 */
		Scanner x=new Scanner(System.in);
		String sPara=new String();
		sPara=x.next();
		boolean mm=aa.isMail(sPara);
		System.out.print("该邮箱地址的状态为:"+mm);
		/*
		 * 判断邮箱是否书写正确
		 */
		String aPara=new String();
		aPara=x.next();
		mm=aa.isNum(aPara);
		System.out.print("该邮箱的数学状态为:"+mm);
		/*
		 * 判断数字
		 */
	}
}

  

posted @ 2019-04-13 14:48  一个人的姐姐  阅读(333)  评论(0编辑  收藏  举报