java实现随机中文
2024-10-20 13:52:41
原文: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
最新文章
- AspNetPager 多条件分页查询
- java 时间操作
- php执行root命令
- for循环求交集
- java web _BBS
- BOM(Bill of Material)详解
- Docker基础技术:Linux CGroup
- iPhone(iOS设备) 无法更新或恢复时, 如何进入恢复模式
- HTML5 修改浏览器url而不刷新页面
- 2437: [Noi2011]兔兔与蛋蛋 - BZOJ
- Binary search for the first element greater than target
- hdu-3790最短路径问题
- BZOJ 3446: [Usaco2014 Feb]Cow Decathlon( 状压dp )
- 你真的了解JAVA中与Webservice相关的规范和实现吗?
- mrql初级教程-使用(er)
- 讨论MMU
- AndroidStudio运行java的main方法
- 由PHP实现单向链表引发的对象赋值,对象传参,链表操作引发的一系列问题
- 【2017山东day7】养猫
- CentOS 7 安装MongoDB详细步骤