public class Test7 {
/**
* 画图演示
* 需求:统计大串中小串出现的次数
* 这里的大串和小串可以自己根据情况给出
*/
public static void main(String[] args) {
//demo1();
// demo2();
/*String str = "abcdefg";
char[] c = str.toCharArray();
for (int i = 0; i < c.length ; i++) {
String s = String.valueOf(c[i] + '1');
System.out.println(s);
}*/
//char c = 'a' + '0';
// Integer i = 100;
//Character s = new Character(c);
char c = 'a' + '1';
System.out.println((char)11);
}
private static void demo2() {
//第二种方法
//定义大串
String max = "woailaopo,laopoyeaiwo,laopofeichangaiwo,shifeichangfeichangdeaiwo";
//定义小串
String min = "laopo";
//indexOf();用这个方法来进行判断大串包含小串
//计数器
int count = 0;
int index = 0;
while(true) {
if(index != -1) {
index = max.indexOf(min , index+min.length());
count++;
}else {
break;
}
}
System.out.println(count);
}
private static void demo1() {
//定义大串
String max = "woailaopo,laopoyeaiwo,laopofeichangaiwo,shifeichangfeichangdeaiwo";
//定义小串
String min = "laopo";
//定义一个计数器变量
int count = 0;
//定义索引
int index = 0;
//定义循环,判断小串是否在大串中出现 出现了则获取 索引,截取 字符串,进行第二次判断。
while((index = max.indexOf(min)) != -1){
count++;//计数器自增
max = max.substring(index + min.length());
}
System.out.println(count);
}
} |
|