package cn.itcast.demo8;
public class Test {
public static void main(String[] args) {
getCount("AeDASa1Daa44s2dasd123213");
System.out.println(getCovert("acCSAXAsa"));
int i = getStringCount("hellojava,nihaojava,javazhenbang,java", "java");
System.out.println(i);
}
/*
* 计算一串字符串中 出现指定字符串出现的次数
*/
public static int getStringCount(String str,String key){
int count = 0;
int index = 0; //判断字符后是否还有字符
while((index = str.indexOf(key))!= -1){
count++;
//获取索引的位置,加上要找字符串的长度,截取它们地址对应长度以后额字符串,继续查找
str = str.substring(index+key.length());
}
return count;
}
/*
* 将字符串第一个字母转换为大写,剩下的转换为小写
*/
public static String getCovert(String str){
String first = str.substring(0,1); //接受字符串,第一个字符
String after = str.substring(1); //接受字符串第一个字符后的所有字符
first = first.toUpperCase(); //转换大写字母
after = after.toLowerCase(); //转换小写字母
return first+after;
}
/*
* 判断一个字符串中有几个大写祖母,小写字母,和数字
*/
public static void getCount(String str){
int upper = 0;
int lower = 0;
int digit = 0;
for(int i = 0; i < str.length(); i++){
char c = str.charAt(i); //chatAt 接收字符串第一个字符
if(c >= 'A' && c <='Z'){
upper++;
}else if(c >= 'a' && c <= 'z'){
lower++;
}else if(c >= '0' && c <='9'){
digit++;
}
}
System.out.println(upper);
System.out.println(lower);
System.out.println(digit);
}
private static int charAt(int i) {
return 0;
}
}
public class Test {
public static void main(String[] args) {
getCount("AeDASa1Daa44s2dasd123213");
System.out.println(getCovert("acCSAXAsa"));
int i = getStringCount("hellojava,nihaojava,javazhenbang,java", "java");
System.out.println(i);
}
/*
* 计算一串字符串中 出现指定字符串出现的次数
*/
public static int getStringCount(String str,String key){
int count = 0;
int index = 0; //判断字符后是否还有字符
while((index = str.indexOf(key))!= -1){
count++;
//获取索引的位置,加上要找字符串的长度,截取它们地址对应长度以后额字符串,继续查找
str = str.substring(index+key.length());
}
return count;
}
/*
* 将字符串第一个字母转换为大写,剩下的转换为小写
*/
public static String getCovert(String str){
String first = str.substring(0,1); //接受字符串,第一个字符
String after = str.substring(1); //接受字符串第一个字符后的所有字符
first = first.toUpperCase(); //转换大写字母
after = after.toLowerCase(); //转换小写字母
return first+after;
}
/*
* 判断一个字符串中有几个大写祖母,小写字母,和数字
*/
public static void getCount(String str){
int upper = 0;
int lower = 0;
int digit = 0;
for(int i = 0; i < str.length(); i++){
char c = str.charAt(i); //chatAt 接收字符串第一个字符
if(c >= 'A' && c <='Z'){
upper++;
}else if(c >= 'a' && c <= 'z'){
lower++;
}else if(c >= '0' && c <='9'){
digit++;
}
}
System.out.println(upper);
System.out.println(lower);
System.out.println(digit);
}
private static int charAt(int i) {
return 0;
}
}