package homework;
//2、取出所有人的姓
public class practice_02 {
public static void main(String[] args) {
String str = "张飞,刘备,关羽,曹操,关平,貂蝉";
//先将字符串分割然后存储进数组names
String[] names = str.split(",");
//循环遍历数组
for (String name : names){
//substring(起始下标,结束下标)取出字符串0-1(包含0不包含1)的子字符串
String surname = name.substring(0,1);
System.out.println(surname);
}
}
}
01-28
2493
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交