java基础,String参数方法实现会员注册升级

/**
 * 
 * @author a2643116636
 * @date 2020-04-12
 *
 */
public class phone {
	// 方法
	public boolean consumer(String shenfen, String phone, String zj) {
		boolean com = true;
		if (shenfen.length() == 16 || shenfen.length() == 18) {
			if (phone.length() == 11) {
				String[] sub = zj.split("-");
				if (sub[0].length() == 4 && sub[1].length() == 7) {  // 满足以上足有条件时,结束循环进行输出
					com=false;  // com如果为false则结束
					System.out.println("注册成功!");  
				} else {  // 座机号码区号不为4位,电话号码不为7位时
					System.out.println("座机号码区号必须为4位数,电话号必须为7位数!");
				}
			} else {  // 手机号码长度不为11位数时
				com = true;
				System.out.println("手机号码长度必须是11位!");
			}
		} else {   // 身份证号码不为16或者18位时
			com = true;
			System.out.println("身份证号必须是16位或者18位!");
		}
		return com;
	}
}

// 测试类
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		String shenfen1;
		String phone1;
		String zj1;
		boolean a = false; // 假设con为false
		// 创建对象
		phone s = new phone();

		System.out.println("***欢迎进入注册系统***\n");
		do {
			System.out.println("请输入身份证号码:");
			shenfen1 = input.next();
			System.out.println("请输入手机号码:");
			phone1 = input.next();
			System.out.println("请输入座机号码:");
			zj1 = input.next();
			if (s.consumer(shenfen1, phone1, zj1)) {

			} else {
				break;
			}
		} while (a = true);
	}


	}
发布了10 篇原创文章 · 获赞 0 · 访问量 3

猜你喜欢

转载自blog.csdn.net/a2643116636/article/details/105474769