
正文
java随机生成汉字
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
public static void main(String[] args) {
String str = null;
int hs, ls;
Random random = new Random();
hs = (176 + Math.abs(random.nextInt(39)));
ls = (161 + Math.abs(random.nextInt(93)));
byte[] b = new byte[2];
b[0] = (new Integer(hs).byteValue());
b[1] = (new Integer(ls).byteValue());
try {
str = new String(b, "GBk"); //转成中文
System.out.println(str);;
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}







