zoukankan      html  css  js  c++  java
  • 简单注册功能(未连接数据库)

    package LESSON8;
    import java.util.*;
    public class exercise2 {
        public static void main(String[] args) {
            Scanner sc=new Scanner(System.in);
            System.out.println("请输入用户名:");
            String username=sc.nextLine().trim();//去掉空格
            if (username.length()>=6) {
                char[] c=username.toCharArray();
                boolean bo1=false;
                boolean bo2=false;
                for (int i = 0; i < c.length; i++) {
                    if(Character.isDigit(c[i])){
                        bo1=true;                    
                    }
                    if(Character.isLetter(c[i])){
                        bo2=true;
                    }    
                }
                if(bo1&&bo2){
                    System.out.println("用户名注册成功, 用户名为:"+username);
                    
                }
                else{
                    System.out.println("用户名必须包含字母和数字");                
                }
    //            label:for (int i = 0; i < c.length; i++) {
    //                if(Character.isDigit(c[i]))
    //                {
    //                    for (int j = 0; j < c.length; j++) 
    //                    {
    //                        if(Character.isLetter(c[j]))
    //                        {
    //                            System.out.println("用户名合法");
    //                            System.out.println("用户名为:"+username);
    //                            break label;
    //                        }
    //                        else
    //                        {
    //                            System.out.println("用户名不包含字母");
    //                            break label;
    //                        }                        
    //                    }                    
    //                }
    //                if(i==c.length-1){
    //                    System.out.println("用户名不包含数字");                    
    //                }                                                    
    //                }                                                                    
    //            }
    //            
    //
            }
            else{
                System.out.println("用户名长度不能小于6位");
            }
            
            System.out.println("请输入密码");
            Scanner sc2=new Scanner(System.in);
            boolean bo3=false;
            boolean bo4=false;
            boolean bo5=false;
            String password=sc2.nextLine().trim();
            if(password.length()>=8)
            {
                for (int i = 0; i < password.length(); i++)
                {
                    if(Character.isDigit(password.charAt(i)))
                    {
                        bo3=true;                    
                    }
                    if(Character.isLetter(password.charAt(i)))
                    {
                        bo4=true;
                    }                                    
               }
                if(password.contains("_")||password.contains("$")){
                    bo5=true;                
                }
                if(bo3&&bo4&&bo5)
                {
                    System.out.println("密码注册成功,密码为:"+password);
                    
                }
                else{
                    System.out.println("密码必须包含特殊符合_或者$,英文字母以及数字");
                }
            }
                else
                {
                System.out.println("密码长度必须大于8");            
                }                
        }
    }

  • 相关阅读:
    一个自动打补丁的脱机程序
    OPC 学习交流感想
    串口标准,说说流控制(RTS/CTS/DTR/DSR 你都明白了吗?)
    asp.net中调用COM组件发布IIS时常见错误 80070005解决方案
    可运行XP的最少后台服务配置
    MapGIS 7.0 SP2 企业版 & MapGIS 7.1IMS
    简单认识一下S60系统
    常用正则表达式
    图像处理:遮罩
    office2003中WORD中visio图无法打印中文问题解决方法
  • 原文地址:https://www.cnblogs.com/qfdy123/p/10976419.html
Copyright © 2011-2022 走看看