输出一个字符串中的大写英文字母数,小写英文字母数以及非英文字母(.java)

import java.util.Scanner;

 

public class string1{

  public static void main(String[] args){

    String str; count c = new count();

    Scanner s = new Scanner(System.in);   

    System.out.print("输入需要统计的字符串 :");

    str = s.next();

    if(str == " "){

      System.out.println("Null");     

      // str = s.next(); return;

    }   

    else{

      c.T(str);

    }

  }   

}

class count{

  private int a = 0,b = 0,c = 0;

  public void T(String str){

    for(int i = 0; i < str.length(); i++){

      if((str.charAt(i) >= 'a') && (str.charAt(i) <= 'z')){

        a++;

       }

      else if((str.charAt(i) >= 'A') && (str.charAt(i) <= 'Z')){

        b++;

      }

      else{

        c++;

      }

     }

    System.out.println("字符串中大写字符有:"+b); System.out.println("字符串中小写字符有:"+a); System.out.println("字符串中其他字符有:"+c);

  }

}

posted @ 2010-10-16 15:32  恒~泪  阅读(1725)  评论(0编辑  收藏  举报