class StringUtil {
private String content;
public StringUtil(String content) {
this.content = content;
}
public String getContent() {
return this.content;
}
public String getInfo() { //默认返回值
return this.getContent();
}
}
class StringCount extends StringUtil {
private int nCount;
private int oCount;
public StringCount(String content) {
super(content);
this.countChar(); //构造方法统计
}
public void countChar() {
char [] data = super.getContent().toCharArray();
for (int x = 0 ; x < data.length ; x++) {
if (data[x] == 'n' || data[x] == 'N') {
this.nCount ++ ;
}
if (data[x] == 'o' || data[x] == 'O') {
this.oCount ++ ;
}
}
}
public int getNCount() {
return this.nCount;
}
public int getOCount() {
return this.oCount;
}
public String getInfo() {
return "字母n的个数:" + this.nCount + "、字母o的个数:" +this.oCount;
}
}
public class Main {
public static void main(String [] args) {
StringCount sc = new StringCount("want you to know one thing");
System.out.println(sc.getInfo());
}
}