jAVA取出一句话中某个词_写一个java程序 要去掉句子中的特定词.用split() 和the indexOf()...

共回答了17个问题采纳率:94.1%

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;

public class FilterKeyword {

/**

*

* @param args

*/

private static String key;

private static String sentences;

private static String[] tempStr;

public static void main(String[] args) {

BufferedReader inStr = new BufferedReader(new InputStreamReader(System.in));

System.out.println("Please enter the filtering key: ");

try {

key = inStr.readLine();

System.out.println("Please enter the input sentences: ");

sentences = inStr.readLine();

} catch (IOException e) {

e.printStackTrace();

}

System.out.println("The filtered sentences: ");

//key = "dog";

//sentences = "Many people keep animals at home. Cats and dogs are the most popular. Some people keep snakes, but this is rare. I like dogs the most. They are really cute.";

tempStr = sentences.split("[.] ");

for (String temp : tempStr){

if(temp.indexOf(key)<=0){

if (temp.indexOf(".")<=0)

System.out.println(temp + ".");

else

System.out.println(temp);

}

}

}

}

1年前

2

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值