package reflect;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
public class text1 {
//
//* * A:案例演示
// * 需求:遍历字符串
public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
String s="wdsddcasdcsdg";
char[]chars=s.toCharArray();
for (char c : chars) {
System.out.println(c);
}
}
}
package reflect;
public class Text2 {
/*
*
* A:案例演示
* 需求:统计一个字符串中大写字母字符,小写字母字符,数字字符出现的次数,其他字符出现的次数。
* ABCDEabcd123456!@#$%^
* 分析:字符串是有字符组成的,而字符的值都是有范围的,通过范围来判断是否包含该字符
* 如果包含就让计数器变量自增
*/
public static void main(String[] args) {
String s=" ABCDEabcd123456!@#$%^";
char[] schar=s.toCharArray();
String num="";
StringBuffer sb2=new StringBuffer(num);
String ziMu="";
StringBuilder sb3=new StringBuilder(ziMu);//小写字母u
String ziMu2="";
StringBuilder sb5=new StringBuilder(ziMu2);//大写
String qiTa="";
StringBuilder sb4=new StringBuilder(qiTa);
for (char c : schar) {
if(c>='a'&&c<='z'){
sb3.append(c);
}else if(c>='A'&&c<='Z'){
sb5.append(c);
}else if(c>='0'&&c<='9'){
sb2.append(c);
}else{
sb4.append(c);
}
}
System.out.println(sb2);
System.out.println(sb3);
System.out.println(sb4);
System.out.println(sb5);
}
}
|
|