实现注册

package t20191125;

import java.util.Scanner;

public class Register {
//0:验证成功,-1:用户名或密码长度错误,-2:两次密码不相同
    public int verify(String username,String password,String confirmpassword) {

        if(!password.equals(confirmpassword)) {
            return -2;
        }
        
        if(username.length() < 3 || confirmpassword.length() < 6 ) {
            return -1;
        }
        
        return 0;
    }
    
    public static void main(String[] args) {
        Register r = new Register();
        Scanner input = new Scanner(System.in);
        
        System.out.println("***欢迎进入注册系统***");
        
        String username;
        String password;
        String confirmpassword;
        while(true) {
            System.out.print("请输入用户名:");
            username = input.next();
            System.out.print("请输入密码:");
            password = input.next();
            System.out.print("请再次输入密码:");
            confirmpassword = input.next();
            
            int n = r.verify(username, password, confirmpassword);
            if(n==-1) {
                System.out.println("用户名长度不能小于3,密码长度不能小于6!");
            }else if(n==-2) {
                System.out.println("两次输入的密码不相同!");
            }else {
                System.out.println("注册成功!请牢记用户名和密码。");
                break;
            }
            
            
        }

        
    }
}

 

posted @ 2019-11-25 19:47  王思慧  阅读(157)  评论(0)    收藏  举报