三九宝宝网宝宝教育写作范文

java统计字符串中每个字母有多少个

12月24日 编辑 39baobao.com

[26英文字母蕴涵的管理哲学]看到题目就知道做管理不易,因为有这么多任务要完成。而笔者本来还想声明,因为字母只有26个,无法全面概括管理中的问题。因此,管理者的选择还是只有用心体悟管理之道,以道应变,则可...+阅读

如下代码提供了三种方式统计一个字符串中出现的大小写字母和其他字符:

class Test{ publicstatic void main(String[] args) { String str = "abAM1,!23"; int cntU = 0; //大写字母的个数 int cntL = 0; //小写字母的个数 int cntOther = 0; int i; //第二种方法 String s1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; String s2 ="abcdefghijklmnopqrstuvwxyz"; for (i=0; i='a' & ch<='z'){// cntL++;// }// elseif (ch>='A' & ch<='Z'){// cntU++;// }// else{// cntOther++;// }// } System.out.printf("大写字母个数: %d\n", cntU); System.out.printf("小写字母个数: %d\n", cntL); System.out.printf("非字母个数: %d\n", cntOther); }}

以下为关联文档:

浅谈英语中的诗歌与字母教学浅谈英语中的诗歌与字母教学 临泽县鸭暖学区小屯小学 田彩兰 字母教学是英语基础教学中的一个重要组成部分。这一阶段的教学教师应给予足够的重视。字母学习如果充满乐趣,学...

java统计字符串的连续子串是回文串的个数import java.util.ArrayList; import java.util.List; public class Palindrome { /* 找出一个字符串中最长的回文子串 * 从字符串中第i个字符开始的所有非空回文子串的个数...

Java题统计字符串字母的个数public static int countLetters(String s) {String str =s; while (!"".equals(str)) { String c = str.substring(0, 1); String tempStr = str.replace(c, ""); System.out.p...

推荐阅读
图文推荐