设一个字符串中包含有大写字母的字符,也有小写字母的字符,编写一个程序,将其中的大小写字母的字符分别输出。

解决方案 »

  1.   

    最笨的方法就是  用ASC 码   一个一个比.
      

  2.   


    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(""));
    }
    }
      

  3.   

    哦 这里呀可以用CharAt方法去吧String类型的转成Char性的再比较
      

  4.   

    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 ++;
    }
    }

    System.out.println("大写:" + cU);
    System.out.println("小写:" + cL);
    System.out.println("其他:" + cO);
    }
    }