怎么传送打包的代码啊!! 我去。。。。。。。
本帖最后由 Lin0411 于 2014-5-1 11:41 编辑
- public class StringCount
- {
- public static void main(String[] args)
- {
- showStringCount("afhh sdfgjk 78469 sdhfg @@");
- }
-
- public static void showStringCount(String str)
- {
- int encount = 0;
- int numcount = 0;
- int spacecount = 0;
- int othercount = 0;
- Map<String,Integer> result = new HashMap<String,Integer>();
- result.put("english", encount);
- result.put("number", numcount);
- result.put("space", spacecount);
- result.put("other", othercount);
-
- char[] strings = str.toCharArray();
-
- for(int i=0; i<strings.length; i++)
- {
- if(((strings[i] <='z') && (strings[i] >= 'a')) || ((strings[i] <= 'Z') && (strings[i] >='A')))
- {
- result.put("english", ++encount);
- }
- else if((strings[i] <='9') && (strings[i] >= '0'))
- {
- result.put("number", ++numcount);
- }
- else if( strings[i] == ' ')
- {
- result.put("space", ++spacecount);
- }
- else
- {
- result.put("other", ++othercount);
- }
- }
-
- Set<String> keySet = result.keySet();
- for(String str1: keySet)
- {
- System.out.print(str1+"("+result.get(str1)+")");
- }
- }
- }
复制代码 |
|