import java.io.UnsupportedEncodingException;
class ChineseConvert {
public String ChineseCap(String ChineseStr) {
byte[] ZW = new byte[2];
long ChineseStr_int;
String CharStr, ChinaStr = "";
CharStr = ChineseStr.substring(0, 1).toString();
try {
ZW = CharStr.getBytes("gb2312");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// 得到汉字符的字节数组
int hightByte = 256 + ZW[0];
int lowByte = 256 + ZW[1];
ChineseStr_int = (256 * hightByte + lowByte) - 256 * 256;
if ((ChineseStr_int >= -20319) && (ChineseStr_int <= -20292)) {
ChinaStr = "A";
} else if ((ChineseStr_int >= -20283)
&& (ChineseStr_int <= -19776)) {
ChinaStr = "B";
} else if ((ChineseStr_int >= -19775)
&& (ChineseStr_int <= -19224)) {
ChinaStr = "C";
} else if ((ChineseStr_int >= -19223)
&& (ChineseStr_int <= -18711)) {
ChinaStr = "D";
} else if ((ChineseStr_int >= -18710)
&& (ChineseStr_int <= -18527)) {
ChinaStr = "E";
} else if ((ChineseStr_int >= -18526)
&& (ChineseStr_int <= -18240)) {
ChinaStr = "F";
} else if ((ChineseStr_int >= -18239)
&& (ChineseStr_int <= -17923)) {
ChinaStr = "G";
} else if ((ChineseStr_int >= -17922)
&& (ChineseStr_int <= -17418)) {
ChinaStr = "H";
}
else if ((ChineseStr_int >= -17417)
&& (ChineseStr_int <= -16475)) {
ChinaStr = "J";
} else if ((ChineseStr_int >= -16474)
&& (ChineseStr_int <= -16213)) {
ChinaStr = "K";
} else if ((ChineseStr_int >= -16212)
&& (ChineseStr_int <= -15641)) {
ChinaStr = "L";
} else if ((ChineseStr_int >= -15640)
&& (ChineseStr_int <= -15166)) {
ChinaStr = "M";
}
else if ((ChineseStr_int >= -15165)
&& (ChineseStr_int <= -14923)) {
ChinaStr = "N";
} else if ((ChineseStr_int >= -14922)
&& (ChineseStr_int <= -14915)) {
ChinaStr = "O";
} else if ((ChineseStr_int >= -14914)
&& (ChineseStr_int <= -14631)) {
ChinaStr = "P";
} else if ((ChineseStr_int >= -14630)
&& (ChineseStr_int <= -14150)) {
ChinaStr = "Q";
}
else if ((ChineseStr_int >= -14149)
&& (ChineseStr_int <= -14091)) {
ChinaStr = "R";
} else if ((ChineseStr_int >= -14090)
&& (ChineseStr_int <= -13319)) {
ChinaStr = "S";
} else if ((ChineseStr_int >= -13318)
&& (ChineseStr_int <= -12839)) {
ChinaStr = "T";
} else if ((ChineseStr_int >= -12838)
&& (ChineseStr_int <= -12557)) {
ChinaStr = "W";
} else if ((ChineseStr_int >= -12556)
&& (ChineseStr_int <= -11848)) {
ChinaStr = "X";
} else if ((ChineseStr_int >= -11847)
&& (ChineseStr_int <= -11056)) {
ChinaStr = "Y";
} else if (ChineseStr_int >= -11055)
{
ChinaStr = "Z";
}
return ChinaStr;
}
}
public class IndexTest {
//输入汉字字符串索引拼音的首字母2008年03月23日 星期日 21:33
public static void main(String[] args) {
ChineseConvert cc = new ChineseConvert();
String[] idx = {"啊啊","毕福剑","朝阳","郑亮","强","留"};
for(int i=0;i<idx.length;i++){
System.out.println(i+"---"+cc.ChineseCap(idx[i]));
}
}
}