请问高手,我是java新手,我想随机生成一个整数,然后根据汉字编码查询对应汉字,不知如何写代码?

 我来答
原来的我MsF
2012-09-06 · TA获得超过182个赞
知道小有建树答主
回答量:141
采纳率:75%
帮助的人:85.3万
展开全部
楼主来瞧瞧我写的 测试已经通过 代码如下 直接复制就可以运行

import java.util.Random;
public class test {
public static void main(String[] args) {
Random r = new Random();
String random =r.nextInt(9999)+"";
String a = CodeToChinese(random);
System.out.println("随机数是 :"+random);
System.out.println("根据随机的区位码得出的是:"+a);
}

public static String CodeToChinese(String code) {
String Chinese = " ";
for (int i = 0; i < code.length(); i += 4) {
byte[] bytes = new byte[2];
String lowCode = code.substring(i, i + 2);
int tempLow = Integer.parseInt(lowCode, 16);
tempLow += 160;
bytes[0] = (byte) tempLow;

String highCode = code.substring(i + 2, i + 4);
int tempHigh = Integer.parseInt(highCode, 16);
tempHigh += 160;
bytes[1] = (byte) tempHigh;

String chara = new String(bytes);
Chinese += chara;
}
return Chinese;

}
}
sbdgvLZLW
2012-09-06 · TA获得超过309个赞
知道小有建树答主
回答量:103
采纳率:100%
帮助的人:121万
展开全部
public static void main(String[] args) {
Random r=new Random();
for (int i = 0; i < 100000; i++) {
char c=(char)r.nextInt(50000);
System.out.println(c);
}
}
本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式