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();
}
}