0
点赞
收藏
分享

微信扫一扫

用Java显示获取每个汉字的拼音首字母

public class

/**
* 根据用户输出的汉字提取出每个汉字的拼音首字母
* @author Ganwb
*
*/

private String getstring;//用户输入的字符串
private String backgetchar="";//用户输入汉字的拼音简码

public void
this.getstring=getstring;
this.getstring.split("");//将字符串转换成数组,数组第0位为""
int length=str.length;//获得数组长度
int start=1;//设置循环初始值
byte[] a=null;
"";//存储汉字拼音首字母
while(start<length){
a=str[start].getBytes();
if(a.length>1){
int asc=256*(a[0]+256)+(a[1]+256);
if(asc>=45217 && asc<=45252){
"A";
else if(asc>=45253 && asc<=45760){
"B";
else if(asc>=45761 && asc<=46317){
"C";
else if(asc>=46318 && asc<=46825){
"D";
else if(asc>=46826 && asc<=47009){
"E";
else if(asc>=47010 && asc<=47296){
"F";
else if(asc>=47297 && asc<=47613){
"G";
else if(asc>=47614 && asc<=48118){
"H";
else if(asc>=48119 && asc<=49061){
"J";
else if(asc>=49062 && asc<=49323){
"K";
else if(asc>=49324 && asc<=49895){
"L";
else if(asc>=49896 && asc<=50370){
"M";
else if(asc>=50371 && asc<=50613){
"N";
else if(asc>=50614 && asc<=50621){
"O";
else if(asc>=50622 && asc<=50905){
"P";
else if(asc>=50906 && asc<=51386){
"Q";
else if(asc>=51387 && asc<=51445){
"R";
else if(asc>=51446 && asc<=52217){
"S";
else if(asc>=52218 && asc<=52967){
"T";
else if(asc>=52698 && asc<=52979){
"W";
else if(asc>=52980 && asc<=53640){
"X";
else if(asc>=53689 && asc<=54480){
"Y";
else if(asc>=54481 && asc<=62289){
"Z";
}
}
else{
getchar=str[start];
}
backgetchar+=getchar;
start++;
}
}

public
return
}

public

return
}

public static void
new
"北京奥运");
System.out.println(cp.getGetstring());
System.out.println(cp.getBackgetchar());
}

}

举报

相关推荐

0 条评论