输入一个英文句子,将每个单词的第一个字母改成大写字母,其它都...
发布网友
发布时间:2024-10-23 18:30
我来回答
共2个回答
热心网友
时间:2024-11-18 02:53
public class A {
public static void main(String[] args) {
System.out.println(In());
}
public static String In(){
Scanner input = new Scanner(System.in);
System.out.println("pls input:");
String words =" "+ input.nextLine();
Pattern pattern = Pattern.compile("\\s+\\S+");
Matcher matcher = pattern.matcher(words);
StringBuilder sbu = new StringBuilder();
while(matcher.find()){
sbu.append(FirstToUp(matcher.group())).append(" ");
}
return sbu.toString();
}
public static String FirstToUp(String name){
if(name == null || "".equals(name))
return "";
String string = name.trim();
return string.substring(0, 1).toUpperCase()+string.substring(1);
}
}
热心网友
时间:2024-11-18 02:54
你这是想实现个什么功能呢