这只是其中的一点点.
例
public class StringTest {
public static void main(String[] args) {
String s = "Hello12345World";
int bigCount = 0;
int smallCount = 0;
int numberCount = 0;
if (ch >= 'A' && ch <= 'Z') {
bigCount++;
} else if (ch >= 'a' && ch <= 'z') {
smallCount++;
} else if (ch >= '0' && ch <= '9') {
numberCount++;
}
}
System.out.println("大写:" + bigCount);
System.out.println("小写:" + smallCount);
System.out.println("数字:" + numberCount);
}
}
例
public static int getCount(String maxString, String minString) {
int count = 0;
int index = maxString.indexOf(minString);
while (index != -1) {
count++
maxString = maxString.substring(index + minString.length());
index = maxString.indexOf(minString);
}
return count;
} |
|