zoukankan      html  css  js  c++  java
  • java实现随机中文

    原文:http://blog.csdn.net/u013926110/article/details/44600601

    public class CreateCheckCode {
        
        /**
         * 生成随机汉字
         * @return
         */
        public static char getRandomChar() {
            String str = "";
            int hightPos;
            int lowPos;
    
            Random random = new Random();
    
            hightPos = (176 + Math.abs(random.nextInt(39)));
            lowPos = (161 + Math.abs(random.nextInt(93)));
    
            byte[] b = new byte[2];
            b[0] = (Integer.valueOf(hightPos)).byteValue();
            b[1] = (Integer.valueOf(lowPos)).byteValue();
    
            try {
                str = new String(b, "GB2312");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
    
            return str.charAt(0);
        }
        
        public static void main(String[] args) {
            
            char[] words = new char[4];
        
            for (int i = 0; i<words.length; i++) {
                words[i] = getRandomChar();
            }
            
            System.out.println(words);
        }
    
    }

    http://blog.csdn.net/u013926110/article/details/44600601

  • 相关阅读:
    第六周 8.23-8.29
    Go-ethereum源码解析-Part I
    Go语言
    UVa Live 4725
    UVa 11134
    UVa 11100
    UVa 11627
    UVa Live 4794
    UVa LA 4254
    UVa 10905
  • 原文地址:https://www.cnblogs.com/shihaiming/p/7670464.html
Copyright © 2011-2022 走看看