随机产生密码

题目:随机产生一个密码,要求同时包含大小写以及数字这三种字符。

import java.util.Arrays;

/**
 * Created by l13560 on 2016/11/14.
 */
public class RandomPasswd {
    public static String randomPasswd(int n){
        if(n<3){
            return null;
        }
        //先把前三位分别给一个小写,一个大写,一个数字,这样后面的就可以完全随机,不用担心没有大小写或者数字了
        char[]passwd=new char[n];
        int ran=(int)(Math.random()*26);
        passwd[0]= (char) ('A'+ran);
        ran=(int)(Math.random()*26);
        passwd[1]=(char) ('a'+ran);
        ran=(int)(Math.random()*10);
        passwd[2]=(char) ('0'+ran);
        for(int i=3;i<n;i++){
            //设置一个随机变量,当随机数等于0时,产生小写,等于1时,产生大写,,
            int rand=(int)(Math.random()*3);
            if(rand==0){
                ran=(int)(Math.random()*26);
                passwd[i]= (char) ('A'+ran);
            }
            if(rand==1){
                ran=(int)(Math.random()*26);
                passwd[i]= (char) ('a'+ran);
            }
            if(rand==2){
                ran=(int)(Math.random()*10);
                passwd[i]= (char) ('0'+ran);
            }
        }
        String randompwd= new String(passwd);
        return randompwd;
    }

    public static void main(String[] args) {
        System.out.println(randomPasswd(10));
    }
}


  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
利用文本随机生成密码if DayOfWeek(now)=1 then Week_Count:=1 else if DayOfWeek(now)=2 then Week_Count:=2 Else if DayOfWeek(now)=3 then Week_Count:=-1 Else if DayOfWeek(now)=4 then Week_Count:=-2 Else if DayOfWeek(now)=5 then Week_Count:=0 Else if DayOfWeek(now)=6 then Week_Count:=2 Else if DayOfWeek(now)=7 then Week_Count:=1; nSbh := Copy(copy(Trim(Cob_smc.Text),pos('>',Cob_smc.Text)+1,10),3,8); If Cob_lx.ItemIndex = 0 then //显示车辆减免 Count_Time := StrToInt(Copy(FormatDateTime('YYYYMMDD',now()),Week_Count+1,7)+Copy(FormatDateTime('YYYYMMDD',now()),1,Week_Count)) else If Cob_lx.ItemIndex = 1 then //显示车辆包缴 Count_Time := StrToInt(Copy(FormatDateTime('YYYYMMDD',now()),Week_Count+4,7)+Copy(FormatDateTime('YYYYMMDD',now()),1,Week_Count+3)) else If Cob_lx.ItemIndex = 2 then //显示车辆死车 Count_Time := StrToInt(Copy(FormatDateTime('YYYYMMDD',now()),Week_Count+5,7)+Copy(FormatDateTime('YYYYMMDD',now()),1,Week_Count+4)) else If Cob_lx.ItemIndex = 3 then //显示车辆联运 Count_Time := StrToInt(Copy(FormatDateTime('YYYYMMDD',now()),Week_Count+2,7)+Copy(FormatDateTime('YYYYMMDD',now()),1,Week_Count+1)) else If Cob_lx.ItemIndex = 4 then //显示车辆统缴 Count_Time := StrToInt(Copy(FormatDateTime('YYYYMMDD',now()),Week_Count+6,7)+Copy(FormatDateTime('YYYYMMDD',now()),1,Week_Count+5)) else If Cob_lx.ItemIndex = 5 then //显示牌证领取 Count_Time := StrToInt(Copy(FormatDateTime('YYYYMMDD',now()),Week_Count+3,7)+Copy(FormatDateTime('YYYYMMDD',now()),1,Week_Count+2)); Count_Sbh:= StrToInt(nSbh);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值