package October;
import java.util.Scanner;
/**
* 输入三个字的名字(拼音)
* 例如 li xing yun,则输出yun,li .L
*/
public class Common {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
//因为scanner.next的默认机制是遇到空格和换行符就会停下
// 加上这行代码改变它的匹配方式,使得它可以接收空格
sc.useDelimiter("\n");
String name = sc.next();
System.out.println(name);
judge(name);
}
public static void judge(String name){
//验证
if(name==null){
throw new RuntimeException("名字不能为空");
}
String[] s = name.split(" ");
//验证
if(s.length!=3){
throw new RuntimeException("名字的长度有误");
}
//改变它的输出格式,.toUpperCase().charAt(0)使中间字大写并读取首字母
String format = String.format("%s,%s .%c", s[2], s[0], s[1].toUpperCase().charAt(0));
System.out.println(format);
}
}
05-05
2746
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
09-21
353
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)