java忽略空格,只计算字母
你能给我们的程序一个想法,忽略空格,只计算字母表,甚至是小的其他明智的上限吗
public class evennumbersloop {
public static void main(String[] args) {
String str = "Hello World uuuu iii pppp jjj";
int count = 0;
for (int i = 0; i <= str.length() - 1; i++) {
if (str.charAt(i) != ' ') {
if (count % 2 == 0) {
String str1 = "";
str1 = str1 + str.charAt(count);
System.out.print(str1.toUpperCase());
} else {
System.out.print(str.charAt(count));
}
count++;
}
}
}
}
# 1 楼答案
你是说
忽略空白并计算出现的字母数>;实际上是没有空格的字符串长度
输出: