//一个字符串,大写字母个数,小写字母个数,其他字符个数(String类)
public class Helloworld1 {
public static void main(String args[]) {
String str = "360 dazhan QQ";
int num2[] = new int[13];
for(int j=0;j<str.length();j++) {
num2[j] = str.codePointAt(j); //将转化后的ASCII值,传给数组
}
int a = 0;
int b = 0;
int c = 0;
for(int k=0;k<num2.length;k++) {
if(num2[k]>96 && num2[k]<123) {
a++;
}else if(num2[k]>64 && num2[k]<91) {
b++;
}else {
c++;
}
}
System.out.println("小写字母数:"+a);
System.out.println("大写字母数:"+b);
System.out.println("其他字符数:"+c);
}
}
....................................................................................................................................
//给定字符串中出现,某一相同字符串的次数(String类)
public class Helloworld1 {
public static void main(String args[]) {
String str = "Hello world word wo wo";
int count = 0;
int index = 0;
while(str.indexOf("wo",index)>0) { //whlie循环(不知道循环的次数的时候用)
index = str.indexOf("wo",index) + 1; //索引跳过已被找到的字符串
count++;
}
System.out.println("出现字符串wo的次数: "+count);
}
}
原文链接: https://www.cnblogs.com/jianzhi20093120/archive/2012/07/17/2596603.html
欢迎关注
微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍
原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/55662
非原创文章文中已经注明原地址,如有侵权,联系删除
关注公众号【高性能架构探索】,第一时间获取最新文章
转载文章受原作者版权保护。转载请注明原作者出处!