密码正则字母数字组合破译游戏 数字转换为字母 有多少种转换方式 java

博客分类:
根据字母取数字,根据数字取字母,主要应用他们之间的asciI码得对应关系
* 数字与字母的转换(1、2、3.....A、B、C、.......)
* @author sg
*/
public class NumberMapLetter {
* 取数字对应的字母
* @param index
public static String getLetter(int index) {
String rs = "";
rs = ((char) (index % 26 + (int) 'A')) +
index = (int) ((index - index % 26) / 26);
} while (index & 0);
* 取字母对应的数字
* @param letter
public static int getNumber(char letter) {
int index = (int)
int start = (int) 'A';
int res = index - start + 1;
public static void main(String[] args) {
System.out.println(getLetter('C'));
guying1028
浏览: 82767 次
来自: 北京
太谢谢你了。。解决了我的问题
更改了之后,退出,再回来
又变回去了 commit也不行
四个菜单在一行显示& 利用频率估计概率知识点 & “(应用创新题)下面给大家介绍密码破译的知...”习题详情
0位同学学习过此题,做题成功率0%
(应用创新题)下面给大家介绍密码破译的知识:密码破译本质上是一个寻找偶然事情规律的一种游戏.为了简明,我们以英语例子加以说明.如果要传递的消息是用英语写的,你可以随意地用两个数字来代替英语中的一个字母,比如为叙述方便,用00,01,02,…25来代替26个英文字母,而每个单词之间用26隔开.当接到这样编排密码时首先要对所有的数码在密码中出现的次数进行统计,算出每个数码出现的频率.再逐步分析出每个数码代表的是哪个字母,弄清了这个问题,密码也就能破译出来了.假如你收到的密码中有一段是:241420你能破译出这段密码吗?&
本题难度:一般
题型:解答题&|&来源:网络
分析与解答
习题“(应用创新题)下面给大家介绍密码破译的知识:密码破译本质上是一个寻找偶然事情规律的一种游戏.为了简明,我们以英语例子加以说明.如果要传递的消息是用英语写的,你可以随意地用两个数字来代替英语中的一个字母,比如为叙...”的分析与解答如下所示:
由题意知,241420破译为H,A,P,P,Y,26,N,E,W,26,Y,E,A,R,26,T,O,26,Y,O,U,∴密码为Happy new Year to you.
找到答案了,赞一个
如发现试题中存在任何错误,请及时纠错告诉我们,谢谢你的支持!
(应用创新题)下面给大家介绍密码破译的知识:密码破译本质上是一个寻找偶然事情规律的一种游戏.为了简明,我们以英语例子加以说明.如果要传递的消息是用英语写的,你可以随意地用两个数字来代替英语中的一个字母...
错误类型:
习题内容残缺不全
习题有文字标点错误
习题内容结构混乱
习题对应知识点不正确
分析解答残缺不全
分析解答有文字标点错误
分析解答结构混乱
习题类型错误
错误详情:
我的名号(最多30个字):
看完解答,记得给个难度评级哦!
经过分析,习题“(应用创新题)下面给大家介绍密码破译的知识:密码破译本质上是一个寻找偶然事情规律的一种游戏.为了简明,我们以英语例子加以说明.如果要传递的消息是用英语写的,你可以随意地用两个数字来代替英语中的一个字母,比如为叙...”主要考察你对“利用频率估计概率”
等考点的理解。
因为篇幅有限,只列出部分考点,详细请访问。
利用频率估计概率
(1)大量重复实验时,事件发生的频率在某个固定位置左右摆动,并且摆动的幅度越来越小,根据这个频率稳定性定理,可以用频率的集中趋势来估计概率,这个固定的近似值就是这个事件的概率.(2)用频率估计概率得到的是近似值,随实验次数的增多,值越来越精确.(3)当实验的所有可能结果不是有限个或结果个数很多,或各种可能结果发生的可能性不相等时,一般通过统计频率来估计概率.
与“(应用创新题)下面给大家介绍密码破译的知识:密码破译本质上是一个寻找偶然事情规律的一种游戏.为了简明,我们以英语例子加以说明.如果要传递的消息是用英语写的,你可以随意地用两个数字来代替英语中的一个字母,比如为叙...”相似的题目:
[2014o防城港o中考]第一次模拟试后,数学科陈老师把一班的数学成绩制成如图的统计图,并给了几个信息:①前两组的频率和是0.14;②第一组的频率是0.02;③自左到右第二、三、四组的频数比为3:9:8,如果成绩不少于90分为优秀,那么全班成绩的优秀率是&&&&%.
[2014o营口o中考]一个不透明的袋中装有若干个红球,为了估计袋中红球的个数,小文在袋中放入10个白球(每个球除颜色外其余都与红球相同).摇匀后每次随机从袋中摸出一个球,记下颜色后放回袋中,通过大量重复摸球试验后发现,摸到白球的频率是27,则袋中红球约为&&&&个.
[2013o北京o中考]第九届中国国际园林博览会(园博会)已于日在北京开幕,以下是根据近几届园博会的相关数据绘制的统计图的一部分.第九届园博会的植物花园区由五个花园组成,其中月季园面积为0.04平方千米,牡丹园面积为&&&&平方千米.
“(应用创新题)下面给大家介绍密码破译的知...”的最新评论
该知识点好题
1在一个不透明的布袋中,红色、黑色、白色的玻璃球共有40个,除颜色外其他完全相同,小明通过多次摸球试验后发现其中摸到红色球、黑色球的频率稳定在15%和45%,则口袋中白色球的个数可能是(  )
2一个口袋中装有10个红球和若干个黄球.在不允许将球倒出来数的前提下,为估计口袋中黄球的个数,小明采用了如下的方法:每次先从口袋中摸出10个球,求出其中红球数与10的比值,再把球放回口袋中摇匀.不断重复上述过程20次,得到红球数与10的比值的平均数为0.4.根据上述数据,估计口袋中大约有&&&&个黄球.
3王老师将1个黑球和若干个白球放入一个不透明的口袋并搅匀,让若干学生进行摸球实验,每次摸出一个球(有放回),下表是活动进行中的一组统计数据.
摸球的次数n&100&150&200&500&800&1000&摸到黑球的次数m&23&31&60&130&203&251&摸到黑球的频率mn&0.23&0.21&0.30&0.26&0.253&&(1)补全上表中的有关数据,根据上表数据估计从袋中摸出一个球是黑球的概率是&&&&;(2)估算袋中白球的个数;(3)在(2)的条件下,若小强同学有放回地连续两次摸球,用画树形图或列表的方法计算他两次都摸出白球的概率.
该知识点易错题
欢迎来到乐乐题库,查看习题“(应用创新题)下面给大家介绍密码破译的知识:密码破译本质上是一个寻找偶然事情规律的一种游戏.为了简明,我们以英语例子加以说明.如果要传递的消息是用英语写的,你可以随意地用两个数字来代替英语中的一个字母,比如为叙述方便,用00,01,02,…25来代替26个英文字母,而每个单词之间用26隔开.当接到这样编排密码时首先要对所有的数码在密码中出现的次数进行统计,算出每个数码出现的频率.再逐步分析出每个数码代表的是哪个字母,弄清了这个问题,密码也就能破译出来了.假如你收到的密码中有一段是:241420你能破译出这段密码吗?”的答案、考点梳理,并查找与习题“(应用创新题)下面给大家介绍密码破译的知识:密码破译本质上是一个寻找偶然事情规律的一种游戏.为了简明,我们以英语例子加以说明.如果要传递的消息是用英语写的,你可以随意地用两个数字来代替英语中的一个字母,比如为叙述方便,用00,01,02,…25来代替26个英文字母,而每个单词之间用26隔开.当接到这样编排密码时首先要对所有的数码在密码中出现的次数进行统计,算出每个数码出现的频率.再逐步分析出每个数码代表的是哪个字母,弄清了这个问题,密码也就能破译出来了.假如你收到的密码中有一段是:241420你能破译出这段密码吗?”相似的习题。博客分类:
1.使用pinyin4j将汉字转成拼音,附件为pinyin4j的jar包
import net.sourceforge.pinyin4j.PinyinH
import net.sourceforge.pinyin4j.format.HanyuPinyinCaseT
import net.sourceforge.pinyin4j.format.HanyuPinyinOutputF
import net.sourceforge.pinyin4j.format.HanyuPinyinToneT
import net.sourceforge.pinyin4j.format.HanyuPinyinVCharT
import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatC
public class ChineseToEnglish {
// 将汉字转换为全拼
public static String getPingYin(String src) {
char[] t1 =
t1 = src.toCharArray();
String[] t2 = new String[t1.length];
HanyuPinyinOutputFormat t3 = new HanyuPinyinOutputFormat();
t3.setCaseType(HanyuPinyinCaseType.LOWERCASE);
t3.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
t3.setVCharType(HanyuPinyinVCharType.WITH_V);
String t4 = "";
int t0 = t1.
for (int i = 0; i & t0; i++) {
// 判断是否为汉字字符
if (java.lang.Character.toString(t1[i]).matches(
"[\\u4E00-\\u9FA5]+")) {
t2 = PinyinHelper.toHanyuPinyinStringArray(t1[i], t3);
t4 += t2[0];
t4 += java.lang.Character.toString(t1[i]);
// System.out.println(t4);
return t4;
} catch (BadHanyuPinyinOutputFormatCombination e1) {
e1.printStackTrace();
return t4;
// 返回中文的首字母
public static String getPinYinHeadChar(String str) {
String convert = "";
for (int j = 0; j & str.length(); j++) {
char word = str.charAt(j);
String[] pinyinArray = PinyinHelper.toHanyuPinyinStringArray(word);
if (pinyinArray != null) {
convert += pinyinArray[0].charAt(0);
convert +=
// 将字符串转移为ASCII码
public static String getCnASCII(String cnStr) {
StringBuffer strBuf = new StringBuffer();
byte[] bGBK = cnStr.getBytes();
for (int i = 0; i & bGBK. i++) {
strBuf.append(Integer.toHexString(bGBK[i] & 0xff));
return strBuf.toString();
public static void main(String[] args) {
System.out.println(getPingYin("綦江qq县"));
System.out.println(getPinYinHeadChar("綦江县"));
System.out.println(getCnASCII("綦江县"));
2.java程序直接转
import java.util.I
import java.util.LinkedHashM
import java.util.S
public class ChineseToEnglish2 {
private static LinkedHashMap spellMap =
if (spellMap == null) {
spellMap = new LinkedHashMap(500);
initialize();
private ChineseToEnglish2() {
private static void spellPut(String spell, int ascii) {
spellMap.put(spell, new Integer(ascii));
private static void initialize() {
spellPut("a", -20319);
spellPut("ai", -20317);
spellPut("an", -20304);
spellPut("ang", -20295);
spellPut("ao", -20292);
spellPut("ba", -20283);
spellPut("bai", -20265);
spellPut("ban", -20257);
spellPut("bang", -20242);
spellPut("bao", -20230);
spellPut("bei", -20051);
spellPut("ben", -20036);
spellPut("beng", -20032);
spellPut("bi", -20026);
spellPut("bian", -20002);
spellPut("biao", -19990);
spellPut("bie", -19986);
spellPut("bin", -19982);
spellPut("bing", -19976);
spellPut("bo", -19805);
spellPut("bu", -19784);
spellPut("ca", -19775);
spellPut("cai", -19774);
spellPut("can", -19763);
spellPut("cang", -19756);
spellPut("cao", -19751);
spellPut("ce", -19746);
spellPut("ceng", -19741);
spellPut("cha", -19739);
spellPut("chai", -19728);
spellPut("chan", -19725);
spellPut("chang", -19715);
spellPut("chao", -19540);
spellPut("che", -19531);
spellPut("chen", -19525);
spellPut("cheng", -19515);
spellPut("chi", -19500);
spellPut("chong", -19484);
spellPut("chou", -19479);
spellPut("chu", -19467);
spellPut("chuai", -19289);
spellPut("chuan", -19288);
spellPut("chuang", -19281);
spellPut("chui", -19275);
spellPut("chun", -19270);
spellPut("chuo", -19263);
spellPut("ci", -19261);
spellPut("cong", -19249);
spellPut("cou", -19243);
spellPut("cu", -19242);
spellPut("cuan", -19238);
spellPut("cui", -19235);
spellPut("cun", -19227);
spellPut("cuo", -19224);
spellPut("da", -19218);
spellPut("dai", -19212);
spellPut("dan", -19038);
spellPut("dang", -19023);
spellPut("dao", -19018);
spellPut("de", -19006);
spellPut("deng", -19003);
spellPut("di", -18996);
spellPut("dian", -18977);
spellPut("diao", -18961);
spellPut("die", -18952);
spellPut("ding", -18783);
spellPut("diu", -18774);
spellPut("dong", -18773);
spellPut("dou", -18763);
spellPut("du", -18756);
spellPut("duan", -18741);
spellPut("dui", -18735);
spellPut("dun", -18731);
spellPut("duo", -18722);
spellPut("e", -18710);
spellPut("en", -18697);
spellPut("er", -18696);
spellPut("fa", -18526);
spellPut("fan", -18518);
spellPut("fang", -18501);
spellPut("fei", -18490);
spellPut("fen", -18478);
spellPut("feng", -18463);
spellPut("fo", -18448);
spellPut("fou", -18447);
spellPut("fu", -18446);
spellPut("ga", -18239);
spellPut("gai", -18237);
spellPut("gan", -18231);
spellPut("gang", -18220);
spellPut("gao", -18211);
spellPut("ge", -18201);
spellPut("gei", -18184);
spellPut("gen", -18183);
spellPut("geng", -18181);
spellPut("gong", -18012);
spellPut("gou", -17997);
spellPut("gu", -17988);
spellPut("gua", -17970);
spellPut("guai", -17964);
spellPut("guan", -17961);
spellPut("guang", -17950);
spellPut("gui", -17947);
spellPut("gun", -17931);
spellPut("guo", -17928);
spellPut("ha", -17922);
spellPut("hai", -17759);
spellPut("han", -17752);
spellPut("hang", -17733);
spellPut("hao", -17730);
spellPut("he", -17721);
spellPut("hei", -17703);
spellPut("hen", -17701);
spellPut("heng", -17697);
spellPut("hong", -17692);
spellPut("hou", -17683);
spellPut("hu", -17676);
spellPut("hua", -17496);
spellPut("huai", -17487);
spellPut("huan", -17482);
spellPut("huang", -17468);
spellPut("hui", -17454);
spellPut("hun", -17433);
spellPut("huo", -17427);
spellPut("ji", -17417);
spellPut("jia", -17202);
spellPut("jian", -17185);
spellPut("jiang", -16983);
spellPut("jiao", -16970);
spellPut("jie", -16942);
spellPut("jin", -16915);
spellPut("jing", -16733);
spellPut("jiong", -16708);
spellPut("jiu", -16706);
spellPut("ju", -16689);
spellPut("juan", -16664);
spellPut("jue", -16657);
spellPut("jun", -16647);
spellPut("ka", -16474);
spellPut("kai", -16470);
spellPut("kan", -16465);
spellPut("kang", -16459);
spellPut("kao", -16452);
spellPut("ke", -16448);
spellPut("ken", -16433);
spellPut("keng", -16429);
spellPut("kong", -16427);
spellPut("kou", -16423);
spellPut("ku", -16419);
spellPut("kua", -16412);
spellPut("kuai", -16407);
spellPut("kuan", -16403);
spellPut("kuang", -16401);
spellPut("kui", -16393);
spellPut("kun", -16220);
spellPut("kuo", -16216);
spellPut("la", -16212);
spellPut("lai", -16205);
spellPut("lan", -16202);
spellPut("lang", -16187);
spellPut("lao", -16180);
spellPut("le", -16171);
spellPut("lei", -16169);
spellPut("leng", -16158);
spellPut("li", -16155);
spellPut("lia", -15959);
spellPut("lian", -15958);
spellPut("liang", -15944);
spellPut("liao", -15933);
spellPut("lie", -15920);
spellPut("lin", -15915);
spellPut("ling", -15903);
spellPut("liu", -15889);
spellPut("long", -15878);
spellPut("lou", -15707);
spellPut("lu", -15701);
spellPut("lv", -15681);
spellPut("luan", -15667);
spellPut("lue", -15661);
spellPut("lun", -15659);
spellPut("luo", -15652);
spellPut("ma", -15640);
spellPut("mai", -15631);
spellPut("man", -15625);
spellPut("mang", -15454);
spellPut("mao", -15448);
spellPut("me", -15436);
spellPut("mei", -15435);
spellPut("men", -15419);
spellPut("meng", -15416);
spellPut("mi", -15408);
spellPut("mian", -15394);
spellPut("miao", -15385);
spellPut("mie", -15377);
spellPut("min", -15375);
spellPut("ming", -15369);
spellPut("miu", -15363);
spellPut("mo", -15362);
spellPut("mou", -15183);
spellPut("mu", -15180);
spellPut("na", -15165);
spellPut("nai", -15158);
spellPut("nan", -15153);
spellPut("nang", -15150);
spellPut("nao", -15149);
spellPut("ne", -15144);
spellPut("nei", -15143);
spellPut("nen", -15141);
spellPut("neng", -15140);
spellPut("ni", -15139);
spellPut("nian", -15128);
spellPut("niang", -15121);
spellPut("niao", -15119);
spellPut("nie", -15117);
spellPut("nin", -15110);
spellPut("ning", -15109);
spellPut("niu", -14941);
spellPut("nong", -14937);
spellPut("nu", -14933);
spellPut("nv", -14930);
spellPut("nuan", -14929);
spellPut("nue", -14928);
spellPut("nuo", -14926);
spellPut("o", -14922);
spellPut("ou", -14921);
spellPut("pa", -14914);
spellPut("pai", -14908);
spellPut("pan", -14902);
spellPut("pang", -14894);
spellPut("pao", -14889);
spellPut("pei", -14882);
spellPut("pen", -14873);
spellPut("peng", -14871);
spellPut("pi", -14857);
spellPut("pian", -14678);
spellPut("piao", -14674);
spellPut("pie", -14670);
spellPut("pin", -14668);
spellPut("ping", -14663);
spellPut("po", -14654);
spellPut("pu", -14645);
spellPut("qi", -14630);
spellPut("qia", -14594);
spellPut("qian", -14429);
spellPut("qiang", -14407);
spellPut("qiao", -14399);
spellPut("qie", -14384);
spellPut("qin", -14379);
spellPut("qing", -14368);
spellPut("qiong", -14355);
spellPut("qiu", -14353);
spellPut("qu", -14345);
spellPut("quan", -14170);
spellPut("que", -14159);
spellPut("qun", -14151);
spellPut("ran", -14149);
spellPut("rang", -14145);
spellPut("rao", -14140);
spellPut("re", -14137);
spellPut("ren", -14135);
spellPut("reng", -14125);
spellPut("ri", -14123);
spellPut("rong", -14122);
spellPut("rou", -14112);
spellPut("ru", -14109);
spellPut("ruan", -14099);
spellPut("rui", -14097);
spellPut("run", -14094);
spellPut("ruo", -14092);
spellPut("sa", -14090);
spellPut("sai", -14087);
spellPut("san", -14083);
spellPut("sang", -13917);
spellPut("sao", -13914);
spellPut("se", -13910);
spellPut("sen", -13907);
spellPut("seng", -13906);
spellPut("sha", -13905);
spellPut("shai", -13896);
spellPut("shan", -13894);
spellPut("shang", -13878);
spellPut("shao", -13870);
spellPut("she", -13859);
spellPut("shen", -13847);
spellPut("sheng", -13831);
spellPut("shi", -13658);
spellPut("shou", -13611);
spellPut("shu", -13601);
spellPut("shua", -13406);
spellPut("shuai", -13404);
spellPut("shuan", -13400);
spellPut("shuang", -13398);
spellPut("shui", -13395);
spellPut("shun", -13391);
spellPut("shuo", -13387);
spellPut("si", -13383);
spellPut("song", -13367);
spellPut("sou", -13359);
spellPut("su", -13356);
spellPut("suan", -13343);
spellPut("sui", -13340);
spellPut("sun", -13329);
spellPut("suo", -13326);
spellPut("ta", -13318);
spellPut("tai", -13147);
spellPut("tan", -13138);
spellPut("tang", -13120);
spellPut("tao", -13107);
spellPut("te", -13096);
spellPut("teng", -13095);
spellPut("ti", -13091);
spellPut("tian", -13076);
spellPut("tiao", -13068);
spellPut("tie", -13063);
spellPut("ting", -13060);
spellPut("tong", -12888);
spellPut("tou", -12875);
spellPut("tu", -12871);
spellPut("tuan", -12860);
spellPut("tui", -12858);
spellPut("tun", -12852);
spellPut("tuo", -12849);
spellPut("wa", -12838);
spellPut("wai", -12831);
spellPut("wan", -12829);
spellPut("wang", -12812);
spellPut("wei", -12802);
spellPut("wen", -12607);
spellPut("weng", -12597);
spellPut("wo", -12594);
spellPut("wu", -12585);
spellPut("xi", -12556);
spellPut("xia", -12359);
spellPut("xian", -12346);
spellPut("xiang", -12320);
spellPut("xiao", -12300);
spellPut("xie", -12120);
spellPut("xin", -12099);
spellPut("xing", -12089);
spellPut("xiong", -12074);
spellPut("xiu", -12067);
spellPut("xu", -12058);
spellPut("xuan", -12039);
spellPut("xue", -11867);
spellPut("xun", -11861);
spellPut("ya", -11847);
spellPut("yan", -11831);
spellPut("yang", -11798);
spellPut("yao", -11781);
spellPut("ye", -11604);
spellPut("yi", -11589);
spellPut("yin", -11536);
spellPut("ying", -11358);
spellPut("yo", -11340);
spellPut("yong", -11339);
spellPut("you", -11324);
spellPut("yu", -11303);
spellPut("yuan", -11097);
spellPut("yue", -11077);
spellPut("yun", -11067);
spellPut("za", -11055);
spellPut("zai", -11052);
spellPut("zan", -11045);
spellPut("zang", -11041);
spellPut("zao", -11038);
spellPut("ze", -11024);
spellPut("zei", -11020);
spellPut("zen", -11019);
spellPut("zeng", -11018);
spellPut("zha", -11014);
spellPut("zhai", -10838);
spellPut("zhan", -10832);
spellPut("zhang", -10815);
spellPut("zhao", -10800);
spellPut("zhe", -10790);
spellPut("zhen", -10780);
spellPut("zheng", -10764);
spellPut("zhi", -10587);
spellPut("zhong", -10544);
spellPut("zhou", -10533);
spellPut("zhu", -10519);
spellPut("zhua", -10331);
spellPut("zhuai", -10329);
spellPut("zhuan", -10328);
spellPut("zhuang", -10322);
spellPut("zhui", -10315);
spellPut("zhun", -10309);
spellPut("zhuo", -10307);
spellPut("zi", -10296);
spellPut("zong", -10281);
spellPut("zou", -10274);
spellPut("zu", -10270);
spellPut("zuan", -10262);
spellPut("zui", -10260);
spellPut("zun", -10256);
spellPut("zuo", -10254);
* 获得单个汉字的Ascii.
* @param cn char 汉字字符
* @return int 错误返回 0,否则返回ascii
public static int getCnAscii(char cn) {
byte[] bytes = (String.valueOf(cn)).getBytes();
if (bytes == null || bytes.length & 2 || bytes.length &= 0) { //错误
if (bytes.length == 1) { //英文字符
return bytes[0];
if (bytes.length == 2) { //中文字符
int hightByte = 256 + bytes[0];
int lowByte = 256 + bytes[1];
int ascii = (256 * hightByte + lowByte) - 256 * 256;
return 0; //错误
* 根据ASCII码到SpellMap中查找对应的拼音
* @param ascii int
* 字符对应的ASCII
* @return String
* 拼音,首先判断ASCII是否&0&&160,如果是返回对应的字符,
* &BR&否则到SpellMap中查找,如果没有找到拼音,则返回null,如果找到则返回拼音.
public static String getSpellByAscii(int ascii) {
if (ascii & 0 && ascii & 160) { //单字符
return String.valueOf( (char) ascii);
if (ascii & -20319 || ascii & -10247) { //不知道的字符
Set keySet = spellMap.keySet();
Iterator it = keySet.iterator();
String spell0 =
String spell =
int asciiRang0 = -20319;
int asciiR
while (it.hasNext()) {
spell = (String) it.next();
Object valObj = spellMap.get(spell);
if (valObj instanceof Integer) {
asciiRang = ( (Integer) valObj).intValue();
if (ascii &= asciiRang0 && ascii & asciiRang) { //区间找到
return (spell0 == null) ? spell : spell0;
asciiRang0 = asciiR
* 返回字符串的全拼,是汉字转化为全拼,其它字符不进行转换
* @param cnStr String
* @return String
* 转换成全拼后的字符串
public static String getFullSpell(String cnStr) {
if (null == cnStr || "".equals(cnStr.trim())) {
return cnS
char[] chars = cnStr.toCharArray();
StringBuffer retuBuf = new StringBuffer();
for (int i = 0, Len = chars. i & L i++) {
int ascii = getCnAscii(chars[i]);
if (ascii == 0) { //取ascii时出错
retuBuf.append(chars[i]);
String spell = getSpellByAscii(ascii);
if (spell == null) {
retuBuf.append(chars[i]);
retuBuf.append(spell);
} // end of if spell == null
} // end of if ascii &= -20400
} // end of for
return retuBuf.toString();
* 第一个字取全拼,后面的字取首字母
* @param cnStr
* @return 返回转换后的拼
public static String getFirstSpell(String cnStr) {
if (null == cnStr || "".equals(cnStr.trim())) {
return cnS
char[] chars = cnStr.toCharArray();
StringBuffer retuBuf = new StringBuffer();
for (int i = 0, Len = chars. i & L i++) {
int ascii = getCnAscii(chars[i]);
if (ascii == 0) { //取ascii时出错
retuBuf.append(chars[i]);
String spell = getSpellByAscii(ascii);
if (spell == null) {
retuBuf.append(chars[i]);
if (i == 0) { //第一个字取全拼
retuBuf.append(spell);
else { //后面的字取首字母
retuBuf.append(spell.substring(0, 1));
} // end of for
return retuBuf.toString();
public static void main(String[] args) {
String str = "中华人明共和国Haha";
// 转换成拼音
System.out.println(ChineseToEnglish2.getFullSpell(str));
// 中文第一个字全拼,其余去首字母
System.out.println(ChineseToEnglish2.getFirstSpell(str));
// ascii 转 字母
System.out.println(ChineseToEnglish2.getSpellByAscii(65));
// 字母 转 ascii
System.out.println(ChineseToEnglish2.getCnAscii('0'));
(184.5 KB)
下载次数: 1907
浏览 53819
对于第二种方法,楼主认为汉字是两个字节,实际上,如果本地环境是UTF-8的话,那应该是三个字节。
byte[] bytes = (String.valueOf(cn)).getBytes("");
所以这里需要处理一下,按照什么方式来获取字节,按照楼主的代码,这里就应该是GBK。
byte[] bytes =;
bytes = (String.valueOf(cn)).getBytes("GBK");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
快速回复,仅供参考,来访:。感谢!!!
浏览: 109101 次
来自: 北京
我怎么打出来全部是中文,没有拼音啊
cuisuqiang 写道对于第二种方法,楼主认为汉字是两个字 ...
感谢楼主分享,用上了
liguosheng1994 写道

我要回帖

更多关于 字母数字密码字典 的文章

 

随机推荐