永发信息网

java 题里的 总方法 里X 的参数 传不进去 希望有人帮我改正

答案:2  悬赏:40  手机版
解决时间 2021-08-20 20:23
  • 提问者网友:ミ烙印ゝ
  • 2021-08-20 07:01

import java.util.HashMap;
import java.util.Map;
import java.io;

public class test {

private static String WORD = "0";

private static String SENTENCE = "1";

public static Map<String, Integer> getCount(String str) {
str = str.replace(".", "#");
str = str.replace("?", "#");
str = str.replace("!", "#");

int wordCount = str.split(" ").length;
int sentenceCount = str.split("#").length;
Map<String, Integer> map = new HashMap<String, Integer>();
map.put(WORD, wordCount);
map.put(SENTENCE, sentenceCount);
return map;
}


public static void main(String[] args) throws NumberFormatException, IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String x=Integer.parseInt(br.readLine());
Map<String, Integer> map = getCount(x.readLine(x));
System.out.println("单词数量: "+map.get(WORD));
System.out.println("句子数量: " + map.get(SENTENCE));
}

}

最佳答案
  • 五星知识达人网友:神的生死簿
  • 2021-08-20 07:31

import java.util.HashMap;
import java.util.Map;
import java.io.*;


public class test{


private static String WORD = "0";


private static String SENTENCE = "1";


public static Map<String, Integer> getCount(String str) {
str = str.replace(".", "#");
str = str.replace("?", "#");
str = str.replace("!", "#");


int wordCount = str.split(" ").length;
int sentenceCount = str.split("#").length;
Map<String, Integer> map = new HashMap<String, Integer>();
map.put(WORD, wordCount);
map.put(SENTENCE, sentenceCount);
return map;
}



public static void main(String[] args) throws NumberFormatException, IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String x=br.readLine();
Map<String, Integer> map = getCount(x);
System.out.println("单词数量: "+map.get(WORD));
System.out.println("句子数量: " + map.get(SENTENCE));
}


}

全部回答
  • 1楼网友:怀裏藏嬌
  • 2021-08-20 07:57

String x=Integer.parseInt(br.readLine());

这个有问题哦 X是字符串Integer.parseInt(br.readLine());是整型

我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯