asdfs
public Map<String,Integer> getCharacterNum(String str)
{
//封装一个Map,key为String类型,value为字母数,其中key为UpperChar的value存大写字母数
//key为LowerChar的value存放小写字母数,key为OtherChar的value存放非英文字母数
Map<String,Integer> map = new HashMap<String,Integer>();
int upperValue = 0;
int lowerValue = 0;
int otherValue = 0;
for (int i = 0 ; i < str.length(); i++)
{
if (str.charAt[i] > 'a' && str.charAt[i] < 'z')
{
lowerValue++;
}
else if (str.charAt[i] > 'A' && str.charAt[i] < 'Z')
{
upperValue++;
}
else
{
otherValue++;
}
}
map.put("UpperChar",upperValue);
map.put("LowerChar",lowerValue);
map.put("OtherChar",otherValue);
return map;
}
然后再main()方法中调用这个函数,通过下面这种方式获取其值
Map<String,Integer> map = 对象名.getCharacterNum(inputStr);
int upperNum = (int) map.get("UpperChar");