import java.util.regex.Pattern; public class test { public static void main(String []args){ String temp = "AwWWEssadaWW"; temp.replaceAll("[a-z]", ""); System.out.println(Pattern.compile("[a-z]").matcher(temp).replaceAll("")); System.out.println(Pattern.compile("[A-Z]").matcher(temp).replaceAll("")); } }
哦 这里呀可以用CharAt方法去吧String类型的转成Char性的再比较
public class TestStringCase { public static void main(String[] args) { String s = "ABAabb$&^$#BAAb898B#@%aa"; int cU = 0, cL = 0, cO = 0; for(int i=0; i<s.length(); i++) { char c = s.charAt(i);
if(c >= 'A' && c <= 'Z') { cU ++; } else if( c >= 'a' && c <='z') { cL ++; } else { cO ++; } }
import java.util.regex.Pattern;
public class test {
public static void main(String []args){
String temp = "AwWWEssadaWW";
temp.replaceAll("[a-z]", "");
System.out.println(Pattern.compile("[a-z]").matcher(temp).replaceAll(""));
System.out.println(Pattern.compile("[A-Z]").matcher(temp).replaceAll(""));
}
}
public static void main(String[] args) {
String s = "ABAabb$&^$#BAAb898B#@%aa";
int cU = 0, cL = 0, cO = 0;
for(int i=0; i<s.length(); i++) {
char c = s.charAt(i);
if(c >= 'A' && c <= 'Z') {
cU ++;
} else if( c >= 'a' && c <='z') {
cL ++;
} else {
cO ++;
}
}
System.out.println("大写:" + cU);
System.out.println("小写:" + cL);
System.out.println("其他:" + cO);
}
}