java中怎么搜索一个字符串中的所有英文单词
展开全部
public void test(){java.util.Scanner sc = new java.util.Scanner(System.in);System.out.println("请输入字符串");String str = sc.next();char[] arr = str.toCharArray();java.util.Map map = new java.util.HashMap();for(int i = 0; i = 65 || (int)arr[i] = 97) || ((int)arr[i] <= 122)){for(int j = 0; j < arr.length; j++){if(arr[i] == arr[j]){++count;}}map.put(arr[i]+"", count);}}java.util.Iterator iter = map.keySet().iterator();while (iter.hasNext()) {String key = (String) iter.next();Integer val = map.get(key);System.out.println(key+"出现了:" + val);}System.out.println("输入的字符串为:"+java.util.Arrays.toString(arr));}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询