永发信息网

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

答案:2  悬赏:40  手机版
解决时间 2021-08-20 20:23

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));
}

}

最佳答案

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));
}


}

全部回答

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

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

我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
谁知道《四月一日灵异事件簿--第二季》的片尾
Just me ’ myself and I 啥意思?
人体的血液在结构层次上是属于(  )
局域网掉线 请求帮助
禹州市许昌新生活化妆品(体育公园财富广场西
“潜规则”是什么意思
小球A和B带电荷量均为+Q ,质量为M和2M,用不计
When you find real friends,treasure them,l
请问父母。兄弟姐妹。好朋友。老婆。你们会怎
美国大都会保险怎么样,美国 不报税有什么危险
新蔡县驻马店快乐星汉堡(华星路店)这个地址在
The ( )is the person who runs the shop and
为什么我的QQ一天只可以花一块钱
Wuold you like to go to a football match o
亦舒爱情经典语录,亦舒经典语录微信公众号
推荐资讯
为什么我电脑上的两个qq号的宠物一个上不去一
走四方闯八方的意思,八方集聚的意思是什么字
人类条件反射最突出的特征是?
我在无锡新区城南路32-7号去东亭路怎么走
黄陂区武汉小奓湖钓具(盘龙城店)地址有谁知道
怎么弹吉他、、
This dictionary must be Li Yang’s.改为同
cf谁有70kg的QQ
百合花的诗词,有关百合花的古诗词
积分能送人么
临湘市岳阳临湘市人口计生局怎么去啊,谁知道
为防止触电事故的发生必须采取哪些安全防护措
正方形一边上任一点到这个正方形两条对角线的
阴历怎么看 ?