Copy codeThe Code is as follows: public static void main (String [] args ){
String str = null;
Str = "Gu Liang ";
System. out. println ("Spell =" + toJP (str ));
}
Public static String toJP (String c ){
Char [] chars = c. toCharArray ();
StringBuffer sb = new StringBuffer ("");
For (int I = 0; I <chars. length; I ++ ){
Sb. append (getJP (chars [I]);
}
Return sb. toString (). toUpperCase ();
}
Public static String getJP (char c)
{
Byte [] array = new byte [2];
Try {
Array = String. valueOf (c). getBytes ("gbk ");
} Catch (UnsupportedEncodingException e ){
// TODO Auto-generated catch block
E. printStackTrace ();
}
If (array. length <2) return String. valueOf (c );
Int I = (short) (array [0]-'/0' + 256) * 256 + (short) (array [1]-'/0' + 256 ));
If (I <0xB0A1) return String. valueOf (c );
If (I <0xB0C5) return "";
If (I <0xB2C1) return "B ";
If (I <0xB4EE) return "c ";
If (I <0xB6EA) return "d ";
If (I <0xB7A2) return "e ";
If (I <0xB8C1) return "f ";
If (I <0xB9FE) return "g ";
If (I <0xBBF7) return "h ";
If (I <0xBFA6) return "j ";
If (I <0xC0AC) return "k ";
If (I <0xC2E8) return "l ";
If (I <0xC4C3) return "m ";
If (I <0xC5B6) return "n ";
If (I <0xC5BE) return "o ";
If (I <0xC6DA) return "p ";
If (I <0xC8BB) return "q ";
If (I <0xC8F6) return "r ";
If (I <0 xCBFA) return "s ";
If (I <0 xCDDA) return "t ";
If (I <0xCEF4) return "w ";
If (I <0xD1B9) return "x ";
If (I <0xD4D1) return "y ";
If (I <0xD7FA) return "z ";
Return String. valueOf (c );
}