写一个方法返回值是Map类型:(通过控制台 写进去一行字符,分别统计出其英文字母,空格,数字和其它字符 放到对应的list里面,最终把list放到Map里并返回)
最近老遇到问这个问题的人,我觉定写个蠢一点的办法满足一下大家
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54import java.util.*; public class demo1 { public static void main(String[] args) { Scanner in = new Scanner(System.in); String arr = in.nextLine(); System.out.println(demo(arr)); } public static Map<String, List> demo (String arr ) { String[] arrs = arr.split(" "); Map<String,List> map = new HashMap<>(); List<String> list1 = new LinkedList<>(); List<String> list2 = new LinkedList<>(); List<String> list3 = new LinkedList<>(); List<String> list4 = new LinkedList<>(); for (int i=0;i<arr.length();i++){ if ((arr.charAt(i)>='a'&&arr.charAt(i)<='z')||(arr.charAt(i)>='A'&&arr.charAt(i)<='Z')){ Character character = arr.charAt(i); list1.add(character.toString()); } else if ('0'<=arr.charAt(i)&&'9'>=arr.charAt(i)){ Character character = arr.charAt(i); list3.add(character.toString()); } else if (' '==arr.charAt(i)){ list2.add(" "); } else { Character character = arr.charAt(i); list4.add(character.toString()); } } map.put("character",list1); map.put("space",list2); map.put("other",list4); map.put("number",list3); return map; } }
最后
以上就是甜美大船最近收集整理的关于java 写一个方法返回值是Map类型的全部内容,更多相关java内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复