public class test {
public static void main(String[] args) {
ForeignFormat("jack chen Hk");
}
/**
* 要求:通过介个String类型的方法和格式化输出,实现中文格式姓名向外国姓名格式的转化
* (1)通过String类中的split方法,对中文姓名进行切割
* (2)通过format方法实现对于外国姓名格式的自定义输出
*/
public static void ForeignFormat(String chineseName) {
//Step one
String[] s = chineseName.split(" ");
//Step two
if (s.length != 3) {
throw new RuntimeException("中文名字格式不正确");
}
//Step three
String foreignName = String.format("%s %s .%c", s[2], s[0],
s[1].toUpperCase().charAt(0));
System.out.println(foreignName);
}
}