[小练习] 统计字符串中大写英文字母、小写英文字母、非英文字母数
作者:
大写K | 来源:发表于
2019-10-11 17:34 被阅读0次public class Main {
public static void main(String[] args) {
String s = "1Hello**World!";
char[] array = s.toCharArray();
int lowerCase = 0;
int upperCase = 0;
int nonAlpha = 0;
for (char c : array) {
if (c>=65 && c<=90) {
upperCase++;
} else if (c>=97 && c<=122) {
lowerCase++;
} else {
nonAlpha++;
}
}
System.out.println(upperCase);
System.out.println(lowerCase);
System.out.println(nonAlpha);
}
}
本文标题:[小练习] 统计字符串中大写英文字母、小写英文字母、非英文字母数
本文链接:https://www.haomeiwen.com/subject/mwdxmctx.html
网友评论