我正在尝试将字符串的第一个字符大写。我看过其他关于堆栈溢出的文章,并尝试了 Apache 常用包。但是,输出保持小写,并且未修改。这是我的代码;
package name;
import java.util.Scanner;
import java.lang.Object;
import org.apache.commons.lang3.text.WordUtils;
public class Name {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
System.out.println("What is your first name?");
String first = input.nextLine();
System.out.println("What is your last name?");
String last = input.nextLine();
String full = (first + " " + last);
WordUtils.capitalize(full);
System.out.println("Your name is " + full);
input.close();
}
}
我也试过
System.out.println("What is your first name?");
String first = input.nextLine();
WordUtils.capitalize(first);
System.out.println("What is your last name?");
String last = input.nextLine();
WordUtils.capitalize(last);
System.out.println("Your name is " + first + last);
我尝试使用capitalzieFully,但这也没有产生任何结果。(我知道没有使用 Object ,我只是尝试将其导入为测试)。