/** * Created by Administrator on 2016/11/6. */ public class test2 { public static void main(String[] args)throws IOException{ String str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; str+= str.toLowerCase(); str +="0123456789"; System.out.println(str); char ch = str.charAt(str.length()-1); System.out.println(ch); StringBuffer sb = new StringBuffer(6); for (int i = 0; i <6 ; i++) { char ch2 = str.charAt(new Random().nextInt(str.length())); sb.append(ch2); } System.out.println(sb); } }
生成方法很多,也可以用Math来做