在Java中,将一个单词的最后一个字母大写,并将第一个字母小写
String是一系列字符值的序列。在Java中,String被视为对象。我们有一个由Java提供的String类,用于创建和操作字符串。
We have to convert the first letter of the word to lowercase and last letter of the word to uppercase.
In this article we will see how the first and last letter can be converted into lower and upper case respectively. Let’s explore.
展示一些实例给你看
Instance-1
假设输入字符串是“Hello”
After converting the first letter to lower and last letter to capital, the new string will be “hellO”
Instance-2
Suppose the input string is “Java”
After converting the first letter to lower and last letter to capital, the new string will be “javA”
Instance-3
Suppose the input string is “Programming”
将第一个字母转为小写,最后一个字母转为大写后,新字符串将为“programminG”
Syntax
要获取字符串的长度,Java的String类提供了一个length()方法。
Below is the syntax for that −
str.length(); 登录后复制