题解 | 首字母大写
首字母大写
https://www.nowcoder.com/practice/91f9c70e7b6f4c0ab23744055632467a
import java.util.Scanner;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while(in.hasNextLine()){
String str = in.nextLine();
boolean flag = true;
for(int index = 0;index < str.length();index++){
char c = str.charAt(index);
if(flag && c>='a' && c <= 'z'){
c = (char)('A' - 'a' + c);
flag = false;
}else{
flag = false;
}
if(c==' ' || c=='\t' || c=='\r' || c == '\n'){
flag = true;
}
System.out.print(c);
}
}
}
}
查看11道真题和解析

