package com.oo.liu.demo01;
import java.nio.charset.MalformedInputException;
public class createPassword {
/**
* 此类是随机生成8位数字、英文(大小写)、特殊符号的密码
*/
public static void number() {
/**
* 计算字符串
*/
int n=0;
String reference="QWERTYUIOPASDFGHJKLZXCVBNM1234567890qwertyuiopasdfghjklzxcvbnm!@#$%^&*()";
char[] strarr=reference.toCharArray();//字符串转换成字符
for (int i = 0; i < strarr.length; i++) {
n++;
}
System.out.println("字符串个数:"+n);
}
public static void passRandom() {
String pass=null;
String textString="";
String reference="QWERTYUIOPASDFGHJKLZXCVBNM1234567890qwertyuiopasdfghjklzxcvbnm!@#$%^&*()";
StringBuffer buffer=new StringBuffer(reference);
System.out.println(buffer.charAt(23));
for (int i = 0; i < 8; i++) {
//随机产生0-72的数字
int ran=(int)(Math.random()*72);
//buffer.charAt()是索引该位置的字符
textString+=buffer.charAt(ran);
}
System.out.println(textString);
}
public static void main(String[] args) {
passRandom();
}
}