第15章上机练习2

package cn.bdqn.com;

import java.util.Scanner;

public class shangji2222 {
	Scanner input = new Scanner(System.in);

	public boolean verify(String num, String sun, String qu) {
		boolean flag = false;
		String[] sz = new String[2];
		sz = qu.split("-");
		if (!(num.length() == 16) && !(num.length() == 18)) {
			System.out.println("身份证号必须是16位或18位!");
		} else if (!(sun.length() == 11)) {
			System.out.println("手机号必须是11位!");
		} else if (!(sz[0].length() == 4) || !(sz[1].length() == 7)) {
			System.out.println("区号必须是4位,电话号码必须是7位");
		} else {
			System.out.println("注册成功!");
			flag = true;
		}
		return flag;
	}

}




package cn.bdqn.com;

import java.util.Scanner;

public class shangji2222222222222222222 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		shangji2222 v = new shangji2222();
		Scanner input = new Scanner(System.in);
		boolean flag = false;
		do{
			System.out.println("请输入身份证:");
			String num=input.next();
			System.out.println("请输入手机号:");
			String sun=input.next();
			System.out.println("输入区号:");
			String qu=input.next();
		/*	System.out.println("请输入座机号:");
			String hao=input.next();*/
			flag=v.verify(num,sun,qu);
		}while(!flag);
	}

}

你可能感兴趣的:(第15章上机练习2)