标题: 说说另外的解法()首字母转大写 [打印本页] 作者: kangnam 时间: 2016-9-16 23:29 标题: 说说另外的解法()首字母转大写 /*
* 将"goOd gooD stUdy dAy dAy up"每个单词的首字母转换成大写其余还是小写字母
* */
public class DayDayUp {
public static void main(String[] args) {
String s ="goOd gooD stUdy dAy dAy up";
//拆分字符串
String[] b =s.split(" ");
for (int i = 0; i < b.length; i++) {
for (int j = 0; j < b[i].length(); j++) {
if(j==0){
//得到第一位字符,转成String类型,再转大写
System.out.print((b[i].charAt(j)+"").toUpperCase());
}else{
System.out.print((b[i].charAt(j)+"").toLowerCase());
}
}
System.out.print(" ");
}
}
}
说说其他解法作者: 15835811325 时间: 2016-9-16 23:37
public static void main(String[] args) {
String s = "goOd gooD stUdy dAy dAy up";
String[] str =s.split(" ");
String k = "";
for (int i = 0; i < str.length; i++) {
String f = str[i];
k +=f.substring(0,1).toUpperCase().concat(f.substring(1).toLowerCase());
}
System.out.println(k);
}作者: kangnam 时间: 2016-9-16 23:50
15835811325 发表于 2016-9-16 23:37
public static void main(String[] args) {
String s = "goOd gooD stUdy dAy dAy up";
String[] str = ...