输入三个字名字的拼音每个字的拼音之间用空格隔开,形式如下:输入—>Java ding zhen
输出—>zhen,Java.D
/**
* @Author Java顶针
* @Version 1.0
*/
public class Test03 {
public static void main(String[] args) {
String name ="wang qing shan";
printName(name);
}
public static void printName(String str){
//1.对输入的字符串进行分割split(“ ”)
if (str == null) {
System.out.println("数组不能为空");
return;
}
String[] names = str.split(" ");
System.out.println(names.length);
if (names.length != 3) {
System.out.println("名字格式不正确");
return;
}
String format = String.format("%s,%s.%c", names[2], names[0],
names[1].toUpperCase().charAt(0));
System.out.println(format);
}
}
标签:练习题,常用,java,String,System,names,println,Java,out
From: https://blog.csdn.net/m0_66130067/article/details/143808518