java小程序。求怎么让首字母变为大写的代码?≥﹏≤

2025-01-24 07:04:19
推荐回答(2个)
回答1:

import java.util.Scanner;

public class UpperWord {
public static void main(String... args){
Scanner scan=new Scanner(System.in);
//String test=scan.toString();
while(scan.hasNext())
{
//System.out.println(scan.next());
for (String str :scan.next().split(" "))
{
str=Character.toUpperCase(str.charAt(0))+str.substring(1, str.length());
System.out.print(str+" ");
}
}
System.out.println();
}

回答2:

"".toUpperCase()