随机生成中文 用程序生成 急啊 在线等 谢谢。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 package com.sigurd.test;import java.util.Random;/** * @author janson_chang * @date 2007-3-7 * @todo 随即生成中文 */public class UnicodeTest { /** * @param args */ public static void main(String[] args) { System.out.println(new String(getCh(getChs(8)))); System.out.println(getChs(8)); } /** * * @param len 传入长度 * @return String */ private static String getChs(int len) { StringBuffer str = new StringBuffer(); String rBase = new String("0123456789abcdef"); for (int i = 0; i < len; i++) { Random rnd = new Random(); int f1, f2, f3, f4; f1 = rnd.nextInt(2) + 11; if (f1 == 13) { f2 = rnd.nextInt(7) + 8; } else { f2 = rnd.nextInt(6) + 9; } f3 = rnd.nextInt(6) + 10; if (f3 == 10) { f4 = rnd.nextInt(14) + 1; } else if (f3 == 15) { f4 = rnd.nextInt(14); } else { f4 = rnd.nextInt(15); } str.append(rBase.substring(f1, f1 + 1) + rBase.substring(f2, f2 + 1) + rBase.substring(f3, f3 + 1) + rBase.substring(f4, f4 + 1)); } System.out.println(str.toString()); return str.toString(); } /** * * @param s 传入的字节字符串转换为中文字节数组 * @return byte[] */ private static byte[] getCh(String s) { byte[] data = new byte[s.length() / 2]; int j = 0; int temp = 0; for (int i = 0; i < s.length(); i++) { temp = Integer.parseInt(s.substring(i, i + 1), 16); temp = temp << 4; i++; temp = temp + Integer.parseInt(s.substring(i, i + 1), 16); data[j] = (byte) temp; j++; } return data; }} Linux下开发JAVA和Windows下开发JAVA有何区别 求一个sql语句 怎么理解属性和方法 对象 类 本人初来乍到,望大家多多帮助! 请问:能不能通过本机上的JAVA应用程序操作远程服务器上的ACCESS数据库? 学习J2ee应该是怎么样的一个顺序比较好 在eclipse下JAVA自动拆装箱的问题 JCreator怎么输入命令行参数?? java中socket通讯的问题(连接过程中怎么判断网络中断?) 用java怎样操作数据库? JAVA打印问题 求救:java程序调用sh脚本没有反应,我错在哪里?
* @author janson_chang
* @date 2007-3-7
* @todo 随即生成中文
*/
public class UnicodeTest { /**
* @param args
*/
public static void main(String[] args) {
System.out.println(new String(getCh(getChs(8))));
System.out.println(getChs(8));
}
/**
*
* @param len 传入长度
* @return String
*/
private static String getChs(int len) {
StringBuffer str = new StringBuffer();
String rBase = new String("0123456789abcdef");
for (int i = 0; i < len; i++) {
Random rnd = new Random();
int f1, f2, f3, f4;
f1 = rnd.nextInt(2) + 11;
if (f1 == 13) {
f2 = rnd.nextInt(7) + 8;
} else {
f2 = rnd.nextInt(6) + 9;
}
f3 = rnd.nextInt(6) + 10;
if (f3 == 10) {
f4 = rnd.nextInt(14) + 1;
} else if (f3 == 15) {
f4 = rnd.nextInt(14);
} else {
f4 = rnd.nextInt(15);
}
str.append(rBase.substring(f1, f1 + 1) + rBase.substring(f2, f2 + 1)
+ rBase.substring(f3, f3 + 1) + rBase.substring(f4, f4 + 1));
}
System.out.println(str.toString());
return str.toString();
}
/**
*
* @param s 传入的字节字符串转换为中文字节数组
* @return byte[]
*/
private static byte[] getCh(String s) {
byte[] data = new byte[s.length() / 2];
int j = 0;
int temp = 0;
for (int i = 0; i < s.length(); i++) {
temp = Integer.parseInt(s.substring(i, i + 1), 16);
temp = temp << 4;
i++;
temp = temp + Integer.parseInt(s.substring(i, i + 1), 16);
data[j] = (byte) temp;
j++;
}
return data;
}
}