package charactor;
public class TestString{
//单词最后一个字母变大写
//注意字符串的长度等于对应字符数组最后的index+1
public static void main(String[] args) {
String word="legendary";
char[] wordarray=word.toCharArray();
char lastletter=wordarray[word.length()-1];
wordarray[word.length()-1]=Character.toUpperCase(lastletter);
for(char x:wordarray) {
System.out.print(x);
}
}
}
Java小练习-单词最后一个字母大写
最新推荐文章于 2021-02-25 20:49:53 发布