public class StudentDemo{ //返回一个Map集合来得到单词和首次出现的下标 key为单词名称 value为单词的角标 public Map<String, Integer> getMap(String str){ Map<String, Integer> map = new HashMap<String, Integer>(); //对str进行分割 再加入map集合中 //请在此添加实现代码 StringTokenizer st=new StringTokenizer(str," ,.?!\n:"); while(st.hasMoreTokens()){ String word=st.nextToken(); if(!map.containsKey(word)){ map.put(word,str.indexOf(word)); } } return map; }

请仔细阅读右侧代码根据方法内的提示在Begin - End区域内进行代码补充具体任务如下:列出给定字符串中每个单词按 !n分割首次出现的位置。测试说明补充完代码后点击测评平台会对你编写的代码进行测试当你的结果与预期输出一致时即为通过。测试输入:No arguments will give courage to the coward预期输出:单词:the---首次出现的角标34单词:No---首次出

原文地址: https://www.cveoy.top/t/topic/dqbO 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录